aspose file tools*
The moose likes Beginning Java and the fly likes why the 'identifier expected' error here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why the Watch "why the New topic
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: 61766
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 61766
    
  67

Without coffee I am a miserable pile of jelly quivering in my chair. I feel for you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why the 'identifier expected' error here?