| Author |
why the 'identifier expected' error here?
|
Thomas Kennedy
Ranch Hand
Joined: Jan 20, 2008
Posts: 137
|
|
Why does the compiler say collx.java:4: <identifier> expected t.add(new Thing("Beaker")); ^ for this code?
|
Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
|
 |
Shiaber Shaam
Ranch Hand
Joined: Jun 16, 2006
Posts: 252
|
|
List<Thing> t = new ArrayList<Thing>(); t.add(new Thing("Beaker")); I don't know what do you mean by <Thing> in the above statements. But, the code should be as shown below, List t = new ArrayList(); t.add(new Thing("Beaker")); Thanks,
|
$Hi/\bEr
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56191
|
|
Originally posted by Shiaber Shaam: I don't know what do you mean by <Thing> in the above statements.
It's the use of Java 1.5 generics and it's perfectly legal.
But, the code should be as shown below,
No, the code statements are fine. The problem is that these statements do not appear within a method or initializer block. That's not valid. The code needs to appear inside a code container.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Thomas Kennedy
Ranch Hand
Joined: Jan 20, 2008
Posts: 137
|
|
|
Thank you! I miss my coffee. I had to cut out all caffeine and I've been more or less brain-damaged ever since.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56191
|
|
|
Without coffee I am a miserable pile of jelly quivering in my chair. I feel for you!
|
 |
 |
|
|
subject: why the 'identifier expected' error here?
|
|
|