User Tools

Site Tools


It appears newer versions of Java tightened up rules on casting. To fix some issues I've seen:

In dump, trying to output members of the elements array can cause casting errors at runtime. A simple workaround is

Object[] elementsCopy = elements;
for (int i = 0; i <= topIndex; i++) {
   System.out.println((Short) elementsCopy[i]);

When using inheritance, prefer calling superclass methods to accessing protected instance variables. For example:

   short x, y, z;
   x =;
   y =;
   z = (short) (x + y); // cast because type of the result is int
cs257e17/proj2.txt · Last modified: 2021/03/09 20:58 by scarl