 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Carramba Guest
|
Posted: Sat Jan 21, 2006 10:42 am Post subject: Syntax error on token "this", invalid ReferenceType |
|
|
Hello,
I have wrote this code in esclipse and I am getting error
"Syntax error on token "this", invalid ReferenceType"
on the second line? could some one explaine why?
public boolean equals(Object f){
if( ( f instanceof this ) && ( this instanceof f )){
if( this.size() == f.size()){
int j=1;
while( j<=this.size()){
if( f[i] == null && this[i] == null ) {
if( this[i] != null && this[i] == f[i] ){
j++;
}
}
}// END WHILE
}// END IF 2
return OK;
}// END IF 1
else return NOTOK;
}// @-->---
--
Thanx in advance
________________________
|
|
| Back to top |
|
 |
Torkel Franzen Guest
|
Posted: Sat Jan 21, 2006 10:43 am Post subject: Re: Syntax error on token "this", invalid ReferenceType |
|
|
Carramba <nospam (AT) note (DOT) com> writes:
| Quote: | Hello,
I have wrote this code in esclipse and I am getting error
"Syntax error on token "this", invalid ReferenceType"
on the second line? could some one explaine why?
public boolean equals(Object f){
if( ( f instanceof this ) && ( this instanceof f )){
|
Your use of instanceof is nonsensical. Check out instanceof in your
favorite text.
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sat Jan 21, 2006 10:52 am Post subject: Re: Syntax error on token "this", invalid ReferenceType |
|
|
On Sat, 21 Jan 2006 11:42:09 +0100, Carramba <nospam (AT) note (DOT) com> wrote,
quoted or indirectly quoted someone who said :
this does not make any sense. It would make sense to same something
like
these[i] where these= new TypeOfThis[n];
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
|
|
| Back to top |
|
 |
Mark Thomas Guest
|
Posted: Sat Jan 21, 2006 4:24 pm Post subject: Re: Syntax error on token "this", invalid ReferenceType |
|
|
Torkel Franzen wrote:
| Quote: | Carramba <nospam (AT) note (DOT) com> writes:
Hello,
I have wrote this code in esclipse and I am getting error
"Syntax error on token "this", invalid ReferenceType"
on the second line? could some one explaine why?
public boolean equals(Object f){
if( ( f instanceof this ) && ( this instanceof f )){
Your use of instanceof is nonsensical. Check out instanceof in your
favorite text.
|
You know what class 'this' is - it's the class your equals() method is
defined in. So if this code is in the Widget class, you could say 'f
instanceof Widget'. If you did want to ensure that 'this' and 'f' were
the same class you could use 'this.getClass() == f.getClass()', but you
really don't need that.
Mark
|
|
| Back to top |
|
 |
opalpa@gmail.com opalinsk Guest
|
Posted: Sat Jan 21, 2006 4:33 pm Post subject: Re: Syntax error on token "this", invalid ReferenceType |
|
|
You got lots of problems with your code man. Your code is
approximately half Java and half something else.
Opalinski
[email]opalpa (AT) gmail (DOT) com[/email]
http://www.geocities.com/opalpaweb/
|
|
| Back to top |
|
 |
Stefan Schulz Guest
|
Posted: Sun Jan 22, 2006 8:34 pm Post subject: Re: Syntax error on token "this", invalid ReferenceType |
|
|
| Quote: | public boolean equals(Object f){
if( ( f instanceof this ) && ( this instanceof f )){
|
Read up on the "instanceof" operator. Hint: What you want to do is
easily achived using getClass == f.getClass()
| Quote: | if( f[i] == null && this[i] == null ) {
if( this[i] != null && this[i] == f[i] ){
|
this[i]? What do you want to do? This is absolutely guaranteed never to
be of an array type (since these are created on the fly by the JVM)
| Quote: | }// END WHILE
}// END IF 2
return OK;
}// END IF 1
else return NOTOK;
}// @-->---
|
Why not use true or false?
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|