Skip to content
Advertisement

Tag: primitive

Integer parameters formula returns integer

Code below makes foo value as -1149239296 i. e. integer value which is out of bounds: Seems like Java takes type of first parameter and tryes to return formula’s result with that type. Where in Java specification one can read that story? I made such suggestion cause actually returns sets long value to foo. Answer For this case, casting any

Byte to “Bit”array

A byte is the smallest numeric datatype java offers but yesterday I came in contact with bytestreams for the first time and at the beginning of every package a marker byte is send which gives further instructions on how to handle the package. Every bit of the byte has a specific meaning so I am in need to entangle the

How can we use .class on primitive types?

When we say it prints class java.lang.Integer which makes sense because java.lang.Integer is a class. So we can have a corresponding Class object. But when I do it prints int which I felt is kind of ambiguous as .class returns an object of type Class and int is not a class (but a primitive type). What is the motive behind

Can Java primitives be considered light objects [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 8 years ago. Improve this question As per this answer here both java objects and primitives go on heap. So from the point of view of JVM,

Java storing two ints in a long

I want to store two ints in a long (instead of having to create a new Point object every time). Currently, I tried this. It’s not working, but I don’t know what is wrong with it: And I’m getting the int values like so: Answer y is getting sign-extended in the first snippet, which would overwrite x with -1 whenever

Dynamically find the class that represents a primitive Java type

I need to make some reflective method calls in Java. Those calls will include methods that have arguments that are primitive types (int, double, etc.). The way to specify such types when looking up the method reflectively is int.class, double.class, etc. The challenge is that I am accepting input from an outside source that will specify the types dynamically. Therefore,

Advertisement