erasure

Why does using raw type variables affect signatures without reference to type-parameters? [duplicate]

自作多情 提交于 2019-11-29 06:13:18
This question already has an answer here: Why does javac complain about generics unrelated to the class' type arguments? [duplicate] 1 answer Looking into another question I bumped into this intriguing behavior of the 1.8.0_112 Sun-Oracle compiler (I have not tested with others): import java.util.List; interface Alpha<T> { List<Integer> intList(); } interface Beta { List<Integer> intList(); } class Main { public static void main(String[] args) { Alpha rawAlpha = null; Alpha<Character> charAlpha = null; Alpha<?> qmAlpha = null; Beta beta = null; for (Integer i : charAlpha.intList()) {} for

Implementing Comparable, compareTo name clash: “have the same erasure, yet neither overrides the other”

痴心易碎 提交于 2019-11-29 03:38:18
I'd like to have a compareTo method that takes a Real (a class for working with arbitrarily large and precise real numbers [well, as long as it's less than 2^31 in length at the moment]) and a compareTo method that takes an Object, but Java isn't letting me and I'm not experienced enough to know why. I just tried to modify the class to implement Comparable and I got these error messages below. I don't really understand what the error messages mean but I know it's got something to do with the horrible way I'm trying to give the class some flexibility with all the different method signatures for

Why does using raw type variables affect signatures without reference to type-parameters? [duplicate]

China☆狼群 提交于 2019-11-27 23:42:38
问题 This question already has an answer here : Why does javac complain about generics unrelated to the class' type arguments? [duplicate] (1 answer) Closed 6 months ago . Looking into another question I bumped into this intriguing behavior of the 1.8.0_112 Sun-Oracle compiler (I have not tested with others): import java.util.List; interface Alpha<T> { List<Integer> intList(); } interface Beta { List<Integer> intList(); } class Main { public static void main(String[] args) { Alpha rawAlpha = null;

Implementing Comparable, compareTo name clash: “have the same erasure, yet neither overrides the other”

穿精又带淫゛_ 提交于 2019-11-27 17:40:55
问题 I'd like to have a compareTo method that takes a Real (a class for working with arbitrarily large and precise real numbers [well, as long as it's less than 2^31 in length at the moment]) and a compareTo method that takes an Object, but Java isn't letting me and I'm not experienced enough to know why. I just tried to modify the class to implement Comparable and I got these error messages below. I don't really understand what the error messages mean but I know it's got something to do with the

How does Gson TypeToken work?

亡梦爱人 提交于 2019-11-27 12:07:36
I understand that in Java contrary to, for example, C# generics are compile-time feature and is removed via type erasure. So, how does Gson's TypeToken really work? How does it get the generic type of an object? From §4.6 of the JLS (emphasis mine): Type erasure is a mapping from types (possibly including parameterized types and type variables) to types (that are never parameterized types or type variables). We write |T| for the erasure of type T. The erasure mapping is defined as follows: The erasure of a parameterized type (§4.5) G is |G|. The erasure of a nested type T.C is |T|.C. The

Pattern matching on generic type in Scala

我与影子孤独终老i 提交于 2019-11-27 04:14:48
I have scala function that looks like this: Now, depending upon the type of T (In my case, it can be Double , Boolean and LocalDate ), I need to apply functions on ob . Something like this (I know the code will make no sense but I am trying to convey what I mean to do): def X[T](ob: Observable[T]): Observable[T] = { //code T match { case Double => DoSomething1(ob:Observable[Double]):Observable[Double] case Boolean => DoSomething2(ob:Observable[Boolean]):Observable[Boolean] case LocalDate => DoSomething3(ob:Observable[LocalDate]):Observable[LocalDate] } } Taking into consideration the Erasure

Pattern matching on generic type in Scala

社会主义新天地 提交于 2019-11-26 11:08:25
问题 I have scala function that looks like this: Now, depending upon the type of T (In my case, it can be Double , Boolean and LocalDate ), I need to apply functions on ob . Something like this (I know the code will make no sense but I am trying to convey what I mean to do): def X[T](ob: Observable[T]): Observable[T] = { //code T match { case Double => DoSomething1(ob:Observable[Double]):Observable[Double] case Boolean => DoSomething2(ob:Observable[Boolean]):Observable[Boolean] case LocalDate =>