• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reflection in jdk1.5?

 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys i hear that there is the concept of reflection in the new jdk 1.5? Does anyone have any ideas how usedul they are?
Saheed.
SCJP 1.5(Coming Monday)..
Imagination is better than Knowledge..
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reflection has been in the Java API since at least Java 1.2 (that's where I started learning the language). It's probably been around longer than that, even.

Basically, reflection allows the programmer to create objects where the class name is dynamic. I'm sure if you use the search tool here at Java Ranch or google for "Java Reflection API", you will find a lot of information about it.

HTH

Layne
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One place to start is Java Tutorial on Reflection API
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But does the new version of Java expand on this? I read somewhere that the 'metadata' of Java was improved but the article did not give any examples, is this one?
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there have been enhancements to the reflection API.
Specifically, the ability to reflect upon annotation types (JSR-175 if I rememebr erectly) and quite possibly, other things.
 
author
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's actually a good bit of reflection in Tiger (Java 5.0, the newest version) that is new. But, you're going to have to deal with something else new, called <i>erasure</i>, that can make life complicated.

In Tiger, you have meta-data called annotations. These allow you to (surprise) annotate your code. So you can indicate if code is unfinished, or should be documented in abnormal ways, or anything else you can come up with.

And, you can reflect into those annotations on runtime code. However, there are some tricky issues, such as when an annotation is retained at runtime (meaning that you can reflect on it), or when they're not. I'm not sure if you wanted more detail on that, but I can provide it if you like.

The other issue is that generics adds some complications to all of this. Because you can declare a type, like for a List (List<String> stringList = new LinkedList<String> , there are some issues that require reflectiont to allow you to check that information out at runtime. But that gets -really- complicated, and is where erasure creeps in.

Erasure, in its simplest form, removes parameterization at runtime. This allows code in a Tiger JVM to play nicely with non-Tiger code, and to remove generics from being a runtime feature. So at runtime, that stringList is just a List, not a List<String>. However, some vagaries of reflection allow you to still get at that information.

So there's a summary -- maybe you want to let me/us know what you're interested in, and we can drill down?

Thanks
Brett
 
Richard Quist
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brett,

If I recall correctly (and I may not ), templates in C++ are implemented by the compiler, which generates scads of code for each specific type/class for which a template is instantiated...

Does Tiger take the same approach?

Thanks
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If I recall correctly (and I may not ), templates in C++ are implemented by the compiler, which generates scads of code for each specific type/class for which a template is instantiated...

Does Tiger take the same approach?



No.
The generics tutorial makes this clear.
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic