Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generic problem  RSS feed

 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to have a map of class, to an instance of the initialisation strategy that initialises it. Is there anyway to do this in Java?

Essentially I want to do something like the following.


Except that it is not legal. I get 'unkown identifier T'.

thanks, Don.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16049
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot use the first line of code outside a class declaration. Is that what you're trying to do? Java does not have global variables that you can declare outside of a class declaration.

You must put the Map inside a generic class:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!