A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
video training course this week in the
Joined: Sep 19, 2003
Dec 23, 2009 18:21:33
I have seen code like below a couple of times now but I am not sure exactly what the <X> X part means. Can anybody explain this to me?
public <X> X get(String key); public <X> X set(String key, X value);
Joined: Nov 24, 2005
Dec 23, 2009 18:40:50
If you only had "public X get(
key);" the compiler would think that X is a real class. However, in your case, X is not a real class, but a generic class. You use <X> to tell the compiler that X is a generic class.
All roads lead to JavaRanch
Joined: Oct 27, 2005
Dec 24, 2009 01:38:51
Generic methods and constructors
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: Method Syntax
reading elements in hashtable in an order
Parameters bound incorrectly
Map 'Like Statement'
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015