Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help2200


This forum is provided to promote discussion amongst students enrolled in Data Structures and Algorithms (CITS2200).
 
Options:
RSS cloud
Jump to:

Unchecked cast from object to E

1 of 251 articles shown, currently no other people reading this forum.
photo
From: ANONYMOUS
Date: Wed 1st Apr, 10:25am
Actions: 
        Login-to-reply
"Xi Rao"                               wrote:

> Hey dude, how did u implement <E> object at the start of code? Like import CITS2200.Deque<E>?

You need simply import CITS2200.Deque, which is an interface that can take a generic parameter

You then want to declare your class:

public class DequeCyclic<E> implements Deque<E> ...

This specifies that your class takes a generic parameter, E, and passess that generic parameter 
into the interface it implements.

Do note that the use of generics is optional and you can instead just use Object. If you do not 
provide a generic parameter, it defaults to Object. Hence Deque<Object> and Deque are the exact 
same thing.

The auto-tester tests your code as just DequeCyclic, so if you implement it using generics it 
will simply test DequeCyclic<Object>, so you can get away with just implementing object 
support.

Related articles

Unchecked cast from object to E (all 4) RSS
├─ original   Tue 24th Mar, 6:11pm, ANONYMOUS
├─ reply 1   Tue 24th Mar, 9:16pm, Xi R.
├─ reply 2   Wed 1st Apr, 10:20am, ANONYMOUS
└─ THIS   Wed 1st Apr, 10:25am, ANONYMOUS
This Page


Program written by: [email protected]
Feedback welcome
Last modified:  8:27am May 24 2020