Why does this code not compile?
public class Wrapper<T> extends T {}
Is it because this is semantically never a proper design choice? Or can this physically not compile in any language because of some sort of type ambiguity?
I'd imagine you could use it to create a public class Persistent<T> extends T {}
that allows you to for example extend the T
with some functionality to serialize the T
to a byte array and store it on disk, while still allowing instances of Persistent<T>
to be passed to functions that would otherwise only take values of type T
.
As such this would be possible:
EDIT: this would not be possible, as there could be no sensible implementation for load()
(as correctly pointed out by michid
). To not corrupt his comment though, I'll leave it here.
Integer i1 = Integer.valueOf(5);
Persistent<Integer> i2= new Persistent<Integer>();
i2.load(i1) //example method to load i1 into i2, basically serializing it
List<Integer> myIntegers = new ArrayList<>();
famousPeople.add(i1);
famousPeople.add(i2);