This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Wildcard character  RSS feed

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand, why the following block of code giving the compile time error:

T means anytype, so why despite of passing the argument like it's still giving the compile time error?
 
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Pawan Arora:
I don't understand, why the following block of code giving the compile time error:

T means anytype, so why despite of passing the argument like it's still giving the compile time error?




No, T is just a template variable. [And you are using it twice as return value...]<-- This was wrong. You CAN declare it like that and then it will take the T from the parameter sent into it...

If I was to create a class of the type that the method resigns in using a String as T the generated method would look like this:



That is okey.

If I use an Integer, the code would translate to:



UPPS!! You can't return a List of Strings when I want you to return a list of Integers.

[ October 16, 2008: Message edited by: Ove Lindstr�m ]
[ October 16, 2008: Message edited by: Ove Lindstr�m ]
 
Sheriff
Posts: 21638
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You either want to return an ArrayList<T>, or change the method signature to remove T and just return List<String>.
 
We noticed he had no friends. So we gave him this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!