How parametrize generic singleton in java -


I have the next problem I have an interface:

  public interface worker & lt ; T & gt; {Public Zero Start (class  increases the tenure); }   

and the implementation of the singleton of this interface:

  public final category listener & lt; T increases the runner & gt; Worker & lt; T & gt; {Private listener () {} @ Override public vowstart (class  increases the term) {...} Public stable listener getInstance () {Return Singleton Holder. INSTANCE; } Private Static Class Singleton Holder {Public stable final listener INSTANCE = new listener (); }}   

My question is, can I get a singleton example like this:

  worker & lt; Thread & gt; Audience = Lister Gate instance ();   

Still the type is safe? When not, how can I use type-safe in the Common Type Singleton instance?

All generics are snatched on runtime.

This means that you are going to be just a stable class singletonhold and only one INSTANCE , whatever is normal.

To get this past, if you understand, you may have 'multiple singlance'. You will need to add some sort of registration, so if you have not yet been able to exist, then make and store it before returning it. Note that this is not compiled, and there may be some problems with it, but the original approach is still the same.

  Public final category listener & lt; T increases the runner & gt; Worker & lt; T & gt; {Private Audience} {} @ Override Public Voice Start (Class & Lt; T & G; Spreads to Task Class) {...} Public Stable Listener Receiving Instance (Class & Lt; t & gt; Claude) {Return Singleton Holder. INSTANCE.get (clause); } Private Static Class Singleton Holder {Private Static Final Map    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -