This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

cast method in class  RSS feed

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a method called cast in Class Class which return an Object;

Am able to see that in my eclipse ide but not in the

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html

Could some one clarify !

If some one has used , please let me see your code snippet !
 
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look here you will find it. Note it says "since 1.5," so it isn't in Java 1.4.
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie:
If you look here you will find it. Note it says "since 1.5," so it isn't in Java 1.4.



Hey Campbell ..


That was a cool introduction - landing to java 1.5.

I never have visited java 1.5

You are my instantiator and loader for Java 1.5 !



Oh My eclipse is 1.5 compatible !

 
Sheriff
Posts: 21741
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 1.4 it won't make any sense to even have the cast method.

The trick about it, is that given a Class<T>, it returns T - or throws a ClassCastException. It's usefull if you need a T but are given something else, like when adding something to a generic collection. Class.isInstance should always go first of course

Now in Java 1.4, it won't make any sense since Class is not generic, and therefore cast could only return Object. You would have to cast it manually again.
 
ram kumar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
In Java 1.4 it won't make any sense to even have the cast method.

The trick about it, is that given a Class<T>, it returns T - or throws a ClassCastException. It's usefull if you need a T but are given something else, like when adding something to a generic collection. Class.isInstance should always go first of course

Now in Java 1.4, it won't make any sense since Class is not generic, and therefore cast could only return Object. You would have to cast it manually again.




Thanks Rob,

Better will stic with java 1.4 then, for this case !

Will see them when i tend to encounter such generic template classes !

Any how that was a great day for introducing me in to java 1.5 !

Thanks Campbell !


 
Campbell Ritchie
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

I don't understand your wish to stick with Java 1.4 however. Java 5 came out almost 4 years ago and you ought to be learning its enhancements.
 
Rob Spoor
Sheriff
Posts: 21741
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. I've been quite hesitant when moving away from Java 1.4, but once I did so I was quite glad I did. Java 6 (which was already available - I totally skipped 5.0!) has so much extra benefits, generics being just one.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!