Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

Syntax error on token "this", invalid ReferenceType

Thread view: 
Carramba - 21 Jan 2006 10:42 GMT
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;
    }// @-->---
Signature


Thanx in advance
________________________

Torkel Franzen - 21 Jan 2006 10:43 GMT
> Hello,
>
[quoted text clipped - 4 lines]
>      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.
Mark Thomas - 21 Jan 2006 16:24 GMT
>>Hello,
>>
[quoted text clipped - 7 lines]
>   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
Roedy Green - 21 Jan 2006 10:52 GMT
>this[i]

this does not make any sense.  It would make sense to same something
like

these[i]  where these= new TypeOfThis[n];

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

opalpa@gmail.com opalinski from opalpaweb - 21 Jan 2006 16:33 GMT
You got lots of problems with your code man.  Your code is
approximately half Java and half something else.

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Stefan Schulz - 22 Jan 2006 20:34 GMT
>      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()

>                      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)

>                  }// END WHILE
>              }// END IF 2
>              return OK;
>          }// END IF 1
>          else return NOTOK;
>      }// @-->---

Why not use true or false?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.