Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Generic Array-list allows to add different data types

 
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

]
It shows some compile time warning why... I am using Java 8
List.png
[Thumbnail for List.png]
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yogesh,
You are getting the compiler error because you aren't using generics. An ArrayList without <> is actually a raw ArrayList, not a generic array list.
 
Ranch Hand
Posts: 145
4
Hibernate Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You are getting the compiler error because you aren't using generics



I think it is not compiler error. It may be just warning by the compiler.
 
Jeanne Boyarsky
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Narayana Bojja wrote:

You are getting the compiler error because you aren't using generics



I think it is not compiler error. It may be just warning by the compiler.


Sorry, yes. I meant compiler warning.
 
yogesh doshi
Ranch Hand
Posts: 49
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still below code is not working

 
Narayana Bojja
Ranch Hand
Posts: 145
4
Hibernate Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your generic ArrayList declaration should be as follows to allow different data types.

Please observe the above generic ArrayList declaration. There is Object as a data type. So you can add any type of object to ArrayList.
If you want to add specific type of objects, you need to specify that type in the ArrayList declaration. Empty sharp brackets at left hand side are not allowed.
Hope this helps !
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic