How to create Classthat represents a shared object?
Class
List<String> list = new List<String>(); Class c1 = list.class; Class c2 = Class.forName(???); // <- how? assert c1 == c2;
A class object does not depend on a specific class that satisfies its type parameter:
assert (new ArrayList<String>()).getClass() == (new ArrayList<Integer>()).getClass();
This is the same object, regardless of how it is typed.
You cannot, because general information is missing at runtime, due to the type of erasure .
Your code can be written as follows:
List<String> list = new ArrayList<String>(); Class c1 = list.getClass(); Class c2 = Class.forName("java.util.ArrayList"); System.out.println(c1 == c2); // true
Class . - java.lang.reflect.Type, ParameterizedType. .
java.lang.reflect.Type
ParameterizedType
(. generics - , . API .)
Source: https://habr.com/ru/post/1792805/More articles:grails spring bean definition - springHow can I manipulate the image using javascript? - javascriptSetting Up Logging with Lift - scalaHow: Bind to DependencyProperty UserControl when UserControl has a DataContext? - c #Django Practice with External Key Queries - djangosqlite & rails: change primary key column? - ruby-on-railsCrash (SIGABRT) when adding a view. (WebView) - objective-cCannot force XDebug to establish a connection in Vim. Getting "no attribue" stop "error - vimHow to rewrite text in VB.NET - overwriteMaven build plugin: excluding files when using the standard descriptor Ref - maven-2All Articles