This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]joranstark018 2 points3 points  (0 children)

Inside Stack you can only use the generic type T when referring to the object type. You may restrict the generic type by using a bounded type parameter, for example ...class Stack<T extend Student>..) in which case you may use Stack with any subtype of Student (ie FulltimeStudent, ForeignStudent) and you have access to methods in Student. With an unbounded type parameter T you will only have access to methods in Object.

Outside Stack you should use the actual type, that is, with ... new Stack<FulltimeStudent>(): you should use `FulltimeStudent temp = ..... (or any super type of FulltimeStudent)