#parameterized types don’t work with the primitive types

1 messages · Page 1 of 1 (latest)

copper cave
#

I'm learning about wrapper classes in arrays, and I found the word "parameterized" is difficult to understand

fading voidBOT
#

<@&987246399047479336> please have a look, thanks.

fading voidBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

copper cave
#

does parameterized mean any type other than primitive types?

#

does wrapper class means using primitive types in other classes called parameterized classes?

#

so when we convert the primitive type to a new type, its called wrapper?

copper cave
vocal sigil
# copper cave why do we need to wrap the primitive type?

Java type system is split in two, you have reference types in a side, and primitives types in the other side
Primitives types don't support methods, inheritance, oop in fact, etc.
And since they don't support that, you sometimes need to use wrappers of those primitives, mostly known as boxed types

copper cave
#

can I write a wrapper class easily?

#

are they just a sub classes?

reef garnet
#

a wrapper is just a word. it's not magic

#

it's just a class that contains the actual thing as field and has a few methods for it

copper cave
reef garnet
#
class Integer {
  private final int value;

  ... 
}
#

and then a bunch of helper methods

#

to convert in either direction

#

which the compiler automatically calls for u for convenience (autoboxing)

#

i. e. when u write
Integer foo = 5;
the compiler replaces it with
Integer foo = Integer.valueOf(5);

#

it's really no magic at all. just regular java code

copper cave
#
    public static void main(String[] args) {
        ArrayList<Integer> lst = new ArrayList<Integer>();
        lst.add(2);
        System.out.println(lst);
    }```
fading voidBOT
copper cave
#

here how can it go back to int?

reef garnet
#

int x = list.get(0);

#

which the compiler replaces with

reef garnet
#

int x = list.get(0).intValue()

#

i mean it's really not different at all to accessing the Integer

copper cave
reef garnet
#

java auto unboxes it

#

the list.get is just how u access the stuff in the list

copper cave
copper cave
reef garnet
#

int a = 5;
Integer b = a;
int c = b;

reef garnet
#

if u have Integer but want int, the compiler automatically calls the methods for u

copper cave
reef garnet
#

the above code is identical to

#

int a = 5;
Integer b = Integer.valueOf(a);
int c = b.intValue();

#

the two snippets are 100% identical

copper cave
#

Thank you Zabuzard

#

I understand it

reef garnet
copper cave
reef garnet
#

who says its good

#

it's different

#

only having objects is easier

#

but therefore slower and needs more memory

#

but python is all interpreted anyways. so it's not really worth to talk about speed and memory anways

#

at least not on that level

copper cave
vocal sigil
copper cave
fading voidBOT
#

Closed the thread.

vocal sigil
#

.

vocal sigil
copper cave
vocal sigil
# copper cave why? if the Idea of java is good, why not other language follow it?

It's not better that's thing, the point of having a splitter type system was so primitive are more efficient but more limited, but java is currently suffering from that
C# at the other, also basically have primitives but handle it better so the system is not split in two
BTW java is going to fix that with project Valhalla, Google it if you want

vocal sigil
copper cave
#

Thank you Alathreon