• 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Generics question.

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Here is a question on generics from Javabeat:

Which method call insert here with argument of ls will allow to compile?

a) m2,m4,m5
b) m1,m2,m3
c) m2,m4,m5
d) m2,m3,m4,m5
e) All will work

My answer is a. But Javabeat answer is d. But how will m3 work since we are passing list of numbers to a method containing list of strings as argument?
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can covert any number to string using toString method.
I think number can be converted into string
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Here ls do not have any generic type declared (legacy code)
In another words compiler allow us to put every kind type of data in it


That means that we also can do this


The fallowing are legal simply because thy are super type of List (List interface IS-A)


Dejan.
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!