Array list casting - Cannot cast Object to char
in
Programming Questions
•
2 years ago
I aways get confused using ArrayList, cause of casting. In reference this is done casting an Object, not a primitive (is this correct char is a primitive right?). Anyway its there "
Ball ball = (Ball) balls.get(i);". Well this do not work with char. Why? How should i do to go around. This code wont run giving a "Cannot cast Object to char." error. Sure you will need a font in data folder... Appreciate any help. Thanks
- ArrayList typed = new ArrayList();
- void setup ()
- {
- size (300,300);
- PFont f = loadFont("CourierNewPS-BoldMT-48.vlw");
- textFont(f,28);
- }
- void draw()
- {
- for (int i=0; i< typed.size();i++) {
- char c = (char) typed.get(i); // Cannot cast Object to char. Why? How to go arround?
- text(c,30,30);
- }
- }
- void keyPressed ()
- {
- typed.add((char)key);
- }
1