Data Types

One Star

Data Types

What's the difference between an Int and Integer in Talend Open Studio. Sometimes it shows one or the other and because of that I seem to get a NullPointerException. Can anyone explain what causes talend to use one over the other.
Thanks
One Star

Re: Data Types

Hi
It seems we have to talk about Java. Smiley Wink
An int is a primitive. It is not an Object. An int is a high performance, streamlined beast for calculating numbers.
An Integer, is a Object that contains a single int field. An Integer is much bulkier than an int. It is sort like a Fedex box to contain the int. Integers are immutable.
Always they will be transfered automatically by JVM.
In TOS, they are the same as Java.
So i don't think they will cause a NullPointerException.
Best regards!
Pedro
Six Stars

Re: Data Types

To add to that, since an "int" is a primitve and not an Object, it does not inherit java.lang.object methods like toSting() or equals() (Lets not get into autoboxing/unboxing) and and cannot be null since null is not a valid integer. This is why when a column in "not nullable" it is an int but when changed to allow nulls becomes an Integer, because it can then be tested against null like 'row1.myInteger == null ? 0 : row1.myInteger'
One Star

Re: Data Types

Ok, so we understand the different between Java's int vs integer. However, the problem is in Talend, not java.
We can't figure out why sometimes Talend uses an "int" (the primitive type) for an int field, and sometimes it has used an "integer". What we want is an "integer" object representation, since it *is* acceptable for the field to have null values. Right now, we have a tmap in which the "left" part of the tmap is using primitive ints; and the right hand is using "integer", and since we have null values in our data, we eventually get "NullPointerExceptions" etc. How can we make all of the Talend int fields into Integer fields?
One Star

Re: Data Types

Ok, so we understand the different between Java's int vs integer. However, the problem is in Talend, not java.
We can't figure out why sometimes Talend uses an "int" (the primitive type) for an int field, and sometimes it has used an "integer". What we want is an "integer" object representation, since it *is* acceptable for the field to have null values. Right now, we have a tmap in which the "left" part of the tmap is using primitive ints; and the right hand is using "integer", and since we have null values in our data, we eventually get "NullPointerExceptions" etc. How can we make all of the Talend int fields into Integer fields?
One Star

Re: Data Types

Hi
When you check 'Nullable' of this column in your schema, you will change int type into Integer.
Best regards!
Pedro