Re: Class Literal ???
TheBigPJ wrote:
---Validation of my understanding---
Your files:
a.class
b.class
c.class
abc.java
abc.class
newsgroup.java
newsgroup.class
By convention, class names should begin with an upper-case letter and be
spelled in "camel case" - mixed case with each word in the compound name
starting with a capital letter.
Class abc{
This will not compile. 'Class' is not a Java keyword.
public void method1 (String theName)
{
//TO DO: Insert if class exists check. try block etc..
Class<Class.forName(theName)> theTempClass = Class.forName(theName); //
No. You can only put types in angle brackets with generics. You put in a
method call, 'forName()'. That's illegal.
What goes into the angle brackets is the base type. For 'Class', it's "What's
the base type of the class?" So 'String' is the base type, the part in angle
brackets, of the type for 'String.class'.
Class <String> clazz = String.class;
It is the "'Class' of base type 'String'".
or is it (Class.forName(theName)).class ?
Also wrong. The class literal can only be used with a type name, not a method
return.
Types only matter at compile time, as Daniel Pitts mentioned.
So metaphorically speaking a bus with people is a good one to use for
'class literal'. The bus is running and while it is running it will
load and unload people. Taking in to account the people can either get
off as they are finished or the bus can throw them off. And taking the
metaphor even further the bus can tell you where it was created from
etc..
Wtf? I feel sure I'd disagree with that characterization if I could
understand it.
--
Lew