raw-types Questions

4

Solved

I want to define a class that implements the generic Comparable interface. While in my class I also defined a generic type element T. In order to implement the interface, I delegate the comparison ...
Averroes asked 4/2, 2014 at 5:35

1

Solved

I am calling a library method that returns a raw Stream. I know the type of the elements in the stream and want to collect into a collection with the declared element type. What is the nice, or the...

1

Solved

Got to implement the method below for an assignment which it's subject is "WildCards", but don't know where to use wildcards in order to resolve the warning. static <T extends Comparable> T ...
Parimutuel asked 31/5, 2020 at 21:57

15

Questions: What are raw types in Java, and why do I often hear that they shouldn't be used in new code? What is the alternative if we can't use raw types, and how is it better?
Crackpot asked 5/5, 2010 at 2:48

5

Solved

Here's a question, this first code listing compiles just fine (JDK 1.6 | JDK 1.7): ArrayList<String> a = new ArrayList<String>(); String[] s = a.toArray(new String[0]); However, if I...
Venetian asked 13/6, 2012 at 3:10

1

Solved

The code below contains a reference to Enum::name (notice no type parameter). public static <T extends Enum<T>> ColumnType<T, String> enumColumn(Class<T> klazz) { return s...
Fever asked 12/5, 2016 at 11:36

4

Solved

Consider the following code: public class Main { public static class NormalClass { public Class<Integer> method() { return Integer.class; } } public static class GenericClass<T>...
Czardas asked 2/5, 2015 at 16:58

6

public class Main { public static void main(String[] args) { ArrayList<Integer> ar = new ArrayList<Integer>(); List l = new ArrayList(); l.add("a"); l.add("b"); ar.addAll(l); Sy...
Veliger asked 24/3, 2015 at 12:55

2

Solved

I did not get this code to compile either way: List<List> a = new ArrayList(); List<List<?>> b = new ArrayList(); a = b; // incompatible types b = a; // incompatible types...
Pneumato asked 14/3, 2015 at 23:31

5

Solved

Here's a code snippet: import java.util.*; class Test { public static void main(String[] args) { List<Integer> list = new ArrayList<>(); addToList(list); Integer i = list.get(0); ...
Insobriety asked 4/3, 2015 at 16:26

2

Solved

I am using Android Studio 1.1.0. This causes no warning: public static class A { public Map<Integer, String> getMap() { return null; } } public static class B { public void processA(A ...
Urethroscope asked 2/3, 2015 at 10:56

3

Solved

A raw list converts to List<?> just fine. Why can't a list of raw lists convert to a list of List<?>? { // works List raw = null; List<?> wild = raw; } { // Type mismatch: cann...
Plane asked 5/11, 2014 at 20:41

1

Solved

I have some code like this: @SuppressWarnings({"unchecked", "rawtypes"}) List<String> theList = new ArrayList(); Is this type-safe? I think it is safe because I don't assign the raw type t...
Instantaneous asked 5/3, 2014 at 16:19

6

Solved

If you create a generic class in Java (the class has generic type parameters), can you use generic methods (the method takes generic type parameters)? Consider the following example: public class...
Floppy asked 1/8, 2013 at 18:15

1

Solved

Can someone explain why this compiles in JDK 1.6, but not in JDK 1.7 from which I get the error message: java: Example is not abstract and does not override abstract method compareTo(java.lang.O...
Girard asked 29/7, 2013 at 10:37

2

Solved

My understanding is that the reason why there are raw types and type erasure in Java is that because at the time generics was introduced, there were standard APIs that could not be made generic wit...
Lillian asked 12/7, 2013 at 13:39

1

Solved

I always thought that primitive types in Java cannot be null, as it is a compile time error if i attempt to do something like this: int test = null; However in a ternary operation, it seems to b...
Wivestad asked 8/11, 2012 at 14:38

4

Solved

this question is partially related to my last question. I have a generic class representing a collection of generic objects: public interface MyObject<N extends Number>{} public interface ...
Concord asked 6/9, 2011 at 23:11

1

I'm using several interfaces with generics types. While combining it together I have some problems when I have to use them from a part of the code that is unaware of the concrete type of the generi...
Reinaldoreinaldos asked 4/9, 2011 at 15:17

5

Solved

Suppose I have a method called foo taking 2 Object as parameter. Both objects are of the same type and both implements comparable interface. void foo(Object first, Object second){ if (!first.get...
Canna asked 10/8, 2011 at 9:33

6

Solved

Possible Duplicate: Java Generics In Eclipse, I am given warnings for using 'rawtypes' and one of it's fixes is to add <?>. For example: Class parameter = String.class; //Ecl...
Declare asked 27/6, 2011 at 14:35

2

Solved

Consider this example: import java.util.*; class Foo<T> { public int baz(List<String> stringlist) { return 1; } public int baz(ArrayList<Object> objectlist) { return 2; } pu...
Feinstein asked 23/5, 2011 at 16:47

4

Solved

I am extending a class defined in a library which I cannot change: public class Parent { public void init(Map properties) { ... } } If I am defining a class 'Child' that extends Parent and I am...
Slavish asked 27/10, 2008 at 22:5

3

Solved

I got a strange compiler error when using generics within a for-each loop in Java. Is this a Java compiler bug, or am I really missing something here? Here is my whole class: public class G...
Proudlove asked 25/3, 2011 at 18:34

2

Solved

I'm writing a wrapper that takes a Scala ObservableBuffer and fires events compatible with the Eclipse/JFace Databinding framework. In the Databinding framework, there is an abstract ObservableLis...
Aime asked 14/2, 2011 at 11:35

© 2022 - 2024 — McMap. All rights reserved.