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 / General / April 2006

Tip: Looking for answers? Try searching our database.

what's the meaning of Class<?> and how to use it

Thread view: 
keepiss - 24 Apr 2006 11:07 GMT
The return type of JTable.getColumnClass(int column) is Class<?>. What
is the meaning of it and how to use it properly? It seems the following
code is okay,

Class c = jTable1.getColumnClass(0);

Is there another way to use Class<?>?
Hendrik Maryns - 24 Apr 2006 11:21 GMT
keepiss schreef:
> The return type of JTable.getColumnClass(int column) is Class<?>. What
> is the meaning of it and how to use it properly? It seems the following
[quoted text clipped - 3 lines]
>
> Is there another way to use Class<?>?

It is used intensively in reflection.  I suggest you keep away from that
a while until you feel you have enough experience to delve into the topic.

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

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
keepiss - 24 Apr 2006 11:54 GMT
I know 'Class' is mainly used in reflection. What I don't understand is
<?>. What does it mean?
Thomas Weidenfeller - 24 Apr 2006 12:11 GMT
> I know 'Class' is mainly used in reflection. What I don't understand is
> <?>. What does it mean?

http://java.sun.com/docs/books/tutorial/extra/generics/index.html

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Thomas Fritsch - 24 Apr 2006 12:36 GMT
> I know 'Class' is mainly used in reflection. What I don't understand is
> <?>. What does it mean?

An attempt to explain <?> is given in
<http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf> (chapter "4
Wildcard").
May be you can make a sense of it. (I don't, but I'm new to generics
anyway :-( )

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Hendrik Maryns - 24 Apr 2006 12:44 GMT
Thomas Fritsch schreef:
>> I know 'Class' is mainly used in reflection. What I don't understand is
>> <?>. What does it mean?
[quoted text clipped - 4 lines]
> May be you can make a sense of it. (I don't, but I'm new to generics
> anyway :-( )

The <T> in Class<T> is the class it actually represents.  So the Class
object belonging to YourClass is Class<YourClass>.  This has all kinds
of advantages in making sure the right class object is given in method
arguments etc.

If a method returns Class<?>, this means it can return any Class object.

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Thomas Fritsch - 24 Apr 2006 13:54 GMT
> Thomas Fritsch schreef:
>>An attempt to explain <?> is given in
[quoted text clipped - 9 lines]
>
> If a method returns Class<?>, this means it can return any Class object.

Ah, thanks! So Class<?> is pretty much the same as Class.

A somewhat related question:
How do I get the concrete semantic meaning of a <T> or <E> parameter
found in the javadoc class declaration? For example in:
  public class Class<T> extends Object

  public interface Collection<E> extends Iterable<E>

Surely we can make clever guesses about what the <T> or <E> parameter in
a particular class is intended to mean, by reading the javadoc of the
methods of that class. But shouldn't there be a more formal description,
too? Might be as a new javadoc tag, for example:
  public class Class<T> extends Object
  @genericparam T  this class

  public interface Collection<E> extends Iterable<E>
  @genericparam E  the type of objects contained in this Collection

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

Hendrik Maryns - 24 Apr 2006 14:39 GMT
Thomas Fritsch schreef:
>> Thomas Fritsch schreef:
>>> An attempt to explain <?> is given in
[quoted text clipped - 11 lines]
>>
> Ah, thanks! So Class<?> is pretty much the same as Class.

Well, yes, it is the generified version.  Class is the erasure type.
Read up on generics if this sounds unclear to you.

Also see
http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#Wha
t%20does%20the%20type%20parameter%20of%20class%20java.lang.Class%20mean
?
shortened: http://tinyurl.com/hk39y

> A somewhat related question:
> How do I get the concrete semantic meaning of a <T> or <E> parameter
> found in the javadoc class declaration? For example in:
>   public class Class<T> extends Object
>
>   public interface Collection<E> extends Iterable<E>

You (almost) can’t.  The information is erased.  At runtime, it is an
Object.  For details and tricks, browse the above site.

> Surely we can make clever guesses about what the <T> or <E> parameter in
> a particular class is intended to mean, by reading the javadoc of the
[quoted text clipped - 5 lines]
>   public interface Collection<E> extends Iterable<E>
>   @genericparam E  the type of objects contained in this Collection

Most of the time, the E will be unknown at the moment the class is
written, thus nothing sensible can be said about it.  Everything you
mention here is indeed in the documentation, and is sort of ‘evident’ as
it is the purpose of generics.  Class is the noticeable exception.

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Thomas Fritsch - 24 Apr 2006 16:39 GMT
> Thomas Fritsch schreef:
>> Surely we can make clever guesses about what the <T> or <E> parameter in
[quoted text clipped - 11 lines]
> mention here is indeed in the documentation, and is sort of ?evident? as
> it is the purpose of generics.  Class is the noticeable exception.

The other noticeable exception from self-evidence is
 public abstract class Enum <E extends Enum<E>>
But AFAIK that class is only for internal use by the compiler (as superclass
of all enum types). Hence incomprehensibility is no problem here. ;-)

Signature

"Thomas:Fritsch$ops.de".replace(':', '.').replace('$', '@')



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.