• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

instanceof

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Integer ii = new Integer(10);
System.out.println(ii instanceof (Object));


The code does not compile....

System.out.println((ii) instanceof Object);
Now it compiles....
why is it so???
 
Swati Kadam
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got the answer..
The code does not compile. It is not allowed to surround the type with parenthesis. You can only surround the object
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I was surprised it compiles either way, but I see (ii) just evaluates to a reference.

It does not compile with the type (Object) in parenthesis, because this is an "illegal start of type."
[ March 11, 2008: Message edited by: marc weber ]
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, who comes up with this stuff? I sure hope this kind of thing doesn't pop up on the exam.

Here's one for you. What does it do?

<_>_ _(_ _){return(_)_;}
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
swati can you please quote the source of your questions it will help..Thanks
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Integer ii = new Integer(10);
System.out.println(ii instanceof Object);

it compiles ~_~
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow Tim,

<_>_ _(_ _){return(_)_;}

looks interesting.

But has compounded my fear of generics.
Generics scare me when wild cards are used.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to write like this .

if( ii instanceof Object ){
........
}
Parenthesis is not allowed .
 
reply
    Bookmark Topic Watch Topic
  • New Topic