__________________
Senast redigerad av john13371337 2013-08-02 kl. 11:39.
Senast redigerad av john13371337 2013-08-02 kl. 11:39.
public interface Foo*T extends Comparable*T** { //.. }
public class FooImpl*T extends Comparable*T** implements Foo*T* { //... private T[] data; public FooImpl(int capacity) { // 1 // data = new T[capacity]; // detta funkar inte (vid kompilering) // 2 data = (T[]) new Comparable[capacity]; // detta fungerar // 3 // data = (T[]) Array.newInstance(T.class, capacity); // kompileringsfel
public interface Foo*T extends Comparable*T** { //.. }
public class FooImpl*T extends Comparable*T** implements Foo*T* { //... private T[] data; public FooImpl(int capacity) { // 1 // data = new T[capacity]; // detta funkar inte (vid kompilering) // 2 data = (T[]) new Comparable[capacity]; // detta fungerar // 3 // data = (T[]) Array.newInstance(T.class, capacity); // kompileringsfel
import java.lang.reflect.Array;
public class Foo<T> {
private T[] data;
public Foo(Class<T> type, int capacity) {
data = (T[])Array.newInstance(type, capacity);
}
}
Du måste vara medlem för att kunna kommentera
Flashback finansieras genom donationer frn vra medlemmar och beskare. Det r med hjlp av dig vi kan fortstta erbjuda en fri samhllsdebatt. Tack fr ditt std!
Swish: 123 536 99 96 Bankgiro: 211-4106