• 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

why the 'identifier expected' error here?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does the compiler say

collx.java:4: <identifier> expected
t.add(new Thing("Beaker"));
^

for this code?

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without coffee I am a miserable pile of jelly quivering in my chair. I feel for you!
 
reply
    Bookmark Topic Watch Topic
  • New Topic