I have been trying to simulate Stack using java classes. here go my class constructor:
public Stack(Class<?> type){
if(type==String.class){
//...
}
switch(type){
case (String.class):
//...
break;
case (Integer.class):
//...
break;
case (Double.class):
//...
break;
case (Byte.class):
//...
break;
default:
break;
}
this.counter = -1;
}
but confusingly for me, the if block works fine. But with the switch/case block it doesn't compile.
error says
incompatible types
switch(type){
^
required: int
found: Class
And
error: constant expression required
case (String.class):
this repeats for all cases in the switch block.
Please kindly point me whether if anything missing here.