Let's say I have the following general class:
public class Foo<T extends Bar> { // stuff }
Is it possible to specify a default type (e.g. Baz ) that will act like T if there was no T in?
Baz
T
No. See "Type Variables" in the Java Language Specification.
However, you can provide subclasses that achieve a similar goal:
public class Foo<T extends Bar> { ... } public class FooDefault extends Foo< Baz > { ... }
Use factory method e.g.
public <T extends Bar> static Foo<T> getInstance(Class<T> clz) { if (clz == null) return new Foo<Bar>; else return clz.newInstance(); }
Source: https://habr.com/ru/post/1388518/More articles:jQuery.ajax () is crashing - jsonIPod Control in Lockscreen for native application - iosPHP If file_get_contents does not work, do it instead - phpError InvalidOperationException - c #How to define multitouch actions in an application for Windows 8? - c #Error Microsoft.WindowsAzure.ServiceRuntime: 102: role environment. INITIALIZATION ERROR - httpssscanf - variable number of format arguments? - cAdvantages / Disadvantages of Increasing AppPool Latency on Azure - asp.netHow to show the contents of a variable that is in the class library in a form or console? - c #How to use Selenium with digest authentication? - seleniumAll Articles