Linked Questions

89 votes
4 answers
122k views

I don't understand the connection between generics and arrays. I can create array reference with generic type: private E[] elements; //GOOD But can't create array object with generic type: elements ...
user2693979's user avatar
  • 2,562
52 votes
3 answers
149k views

I don't understand the error of Generic Array Creation. First I tried the following: public PCB[] getAll() { PCB[] res = new PCB[list.size()]; for (int i = 0; i < res.length; i+...
Luron's user avatar
  • 1,187
5 votes
2 answers
10k views

I have a map private HashMap<Character, Integer> map; I want to convert it to array but when I do that/I get this: Entry<Character, Integer> t = map.entrySet().toArray(); **Type ...
Yoda's user avatar
  • 18.2k
5 votes
4 answers
16k views

Possible Duplicate: Java how to: Generic Array creation How to create an array of type T[] in Java? I can't use Arrays.newInstance() since I have no objects of Class<T>. Is there a generic ...
Dims's user avatar
  • 51.8k
6 votes
3 answers
3k views

Possible Duplicate: Java how to: Generic Array creation Error: Generic Array Creation I am getting this error: Cannot create a generic array of T This is my code (error on line 6): 1 public ...
Pat Murray's user avatar
  • 4,295
8 votes
3 answers
4k views

Possible Duplicate: Java how to: Generic Array creation Error generic array creation I have been tasked with writing a Hash Table in Java, which must work with any data type. The rules on the ...
Tanaki's user avatar
  • 2,635
9 votes
1 answer
2k views

For various reasons I want to convert a list to an array, however the Collection contains objects that are themselves generics. I have tried the following four options to get it to compile without ...
Paul Wagland's user avatar
  • 29.4k
1 vote
3 answers
9k views

Although this code compiles successfully, it throws a class cast exception error at run-time: class Test { public static void main(String[] args) { MyArray<String> x = new MyArray&...
user avatar
1 vote
3 answers
8k views

Possible Duplicate: Java how to: Generic Array creation I want to create a Stack which contains 10 elements, I'm trying to do this with Generics. I started by creating a Stack class of Type T, but ...
tintin's user avatar
  • 5,885
1 vote
4 answers
4k views

Possible Duplicate: Create instance of generic type in Java? Java how to: Generic Array creation I am trying to create a create a class of generic type. This is my class file. public class ...
Rahul's user avatar
  • 47.4k
2 votes
3 answers
5k views

I am having trouble understanding the nuances of generics, interfaces, and arrays and how to use them together. I have an assignment for an intermediate Java class. The assignment is as follows: ...
kevinivan05's user avatar
1 vote
3 answers
2k views

Possible Duplicate: Java how to: Generic Array creation I wanna create something like this: public class MyClass<T> { private int row; private int column; private T[][] result; ...
ruslanys's user avatar
  • 1,211
3 votes
2 answers
697 views

I have this following method: public static <T, U> T[] getKeysForValue(Map<T,U> map,U value){ if(map == null || map.isEmpty()) { return null; } Set<T> keys = ...
Tapas Bose's user avatar
-3 votes
2 answers
2k views

How to make following code completely generic? Why I'm not allowed to write: private E[]store = new E[length]; import java.util.Arrays; public class MyArrayList<E> { private int size = 0; ...
Aniruddha Jagtap's user avatar
0 votes
0 answers
4k views

enter image description here the code is below: package linear_list; public class SeqList<T> { protected int n; protected T[] element; private static final int MIN_CAPACITY=...
Frederick_Chen's user avatar

15 30 50 per page
1
2 3 4 5
21