Note that there are some explanatory texts on larger screens.

plurals
  1. PODo the Java Integer and Double objects have unnecessary overhead?
    text
    copied!<p>I am working with Java 1.3, so it does not support generics. I came up with a shady work around. I want to know if the Integer and Double objects have an unnecessary overhead; I guess what I am asking is: do Integers take up same amount of space as an int? Same question for Double and doubles.</p> <p>From what I know, the array of Objects holds an array of 32 bit integers that actually hold the address to the Object in memory independent of the array. But when I explicitly make an array of primitives like I did here, the outcome would be bad. Because, AFAIK, an array of primitives actually are an array of the data, not the pointers to the data. Or am I just assuming too much from C++? </p> <p>So, if the Array in DataPackage actually does hold pointers instead of the primitives, I am good to go. But if they hold the primitives themselves, accessing the data will be a problem since a double is 64 bits of data, but a pointer to that is still 32 bits. </p> <pre><code>/** * * * @todo Comment all the code. * @author Davidthefat * @version 1.0 */ public class DataPackage { private String dataType; private Object data; /** * * @param type * @param numOfItems */ public DataPackage(String type, int numOfItems) { dataType = type; if (type.equals("Wheels")) { data = new int[numOfItems * 2]; } if (type.equals("Arms")) { data = new int[numOfItems * 1]; } if (type.equals("Joysticks")) { data = new double[numOfItems * 2]; } if (type.equals("Buttons")) { data = new boolean[numOfItems * 4]; } } /** * * @param t1 */ public void update(Object t1) { data = t1; } /** * * @return */ public Object getData() { return data; } /** * * @return */ public String toString() { return "This contains " + dataType; } } </code></pre> <p>To access that data, I cast the array of Objects as an array of Integers then call the intValue() function: temp is an array of ints. I must also put that getData in input just returns a DataPackage.</p> <pre><code>temp[0] = ((Integer[])input.getData("Wheels").getData())[0].intValue(); </code></pre> <p>I can't just run this code right now since this is for the FRC Robot at my school, and school's out. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload