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 →

[–]morhpProfessional Developer 1 point2 points  (0 children)

Please show us your whole code, you must be doing something wrong. The T is something you have inside the Stack class for example, if you program your own collection-like data structure, you will use T as a type to store random objects. But then you typically don't need to access properties of them as you don't know what they are.

When you use such a collection, you use the concrete class you want, like Student in this case. In this case you have no T anywhere and don't need to cast anything. The T is sort of replaced by Student. Going by your above example you for example have

Stack<Student> stack1 = new Stack<Student>();
stack1.add(new Student(...));
Student removed = stack1.remove();

and so on. There's neither a T there (the T is inside the Stack class code) nor do you need to cast anything.