Answer the question
In order to leave comments, you need to log in
Why can't an ArrayDeque be created for Chars?
Let's say I create an ArrayDeque for chars:
ArrayDeque<char> pass_raw = new ArrayDeque<char>();
static public void stackUpper(ArrayDeque<char> pass) {
if (pass.getLast() == 'A') {
pass.addLast('B');
} else {
pass.addLast('A');
}
}
Main.java:5: error: unexpected type
public static void stackUpper(ArrayDeque<char> pass) {
^
required: reference
found: char
Main.java:39: error: unexpected type
ArrayDeque<char> pass_raw = new ArrayDeque<char>();
^
required: reference
found: char
Main.java:39: error: unexpected type
ArrayDeque<char> pass_raw = new ArrayDeque<char>();
^
required: reference
found: char
Answer the question
In order to leave comments, you need to log in
In java, generics cannot use primitives. There are wrapper classes for this. For char it's Character, for int it's Integer, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question