int Vs Integer
Hi,
i have a method like ...
public int args(int s)
{
int s12 = 23;
Integer inte = new Integer(s12);....?
return inte.intValue();
}
this method wrapes the int to Integer ... but there no need on that....
why we wrap the primitive int to Integer actually what is the technical advantage on that (apart from memory issues) !!!!
and when we go for wrapper classes.....
how i can use the wrapper classes...?
for example i have created a customized button like..
public class mybutton extends JButton
{
// here my own overrided methods
}
can i assume the above one is an example of wrapper class which wraps the JButton..!!
-Thanks in advance
-Alex
[766 byte] By [
gw@balaa] at [2007-10-1 0:41:47]

> int s12 = 23;
Roast in hell for giving variables names like this. ;)
> this method wrapes the int to Integer ... but there
> no need on that....
Don't do it then.
> why we wrap the primitive int to Integer actually
> what is the technical advantage on that (apart from
> memory issues) !!!!
Memory issues?
Integers are objects. Elementals aren't. That's the big difference. You can't add elementals toa collection, for instance.
> how i can use the wrapper classes...?
RTFAPI
> can i assume the above one is an example of wrapper
> class which wraps the JButton..!!
That's not wrapping, that's inheritance.
You should get a good book and read it, you know?
> Roast in hell for giving variables names like this. ;)
We can make it worse .. JavaPerl :)public int $var1 = 2;
public int $45 = 3;
public int $var2 = $var1 + $45;
> > Roast in hell for giving variables names like this.> ;)> > We can make it worse .. JavaPerl :)May you be tortured forever by Olivia Newton-John songs, mate... ;-)
> why we wrap the primitive int to Integer actually
> what is the technical advantage on that (apart from
> memory issues) !!!!
It's a consequence of the split type system in Java. Java has two distinct type categories, namely primitives and classes. Java is object oriented so basically the primitives shouldn't be there, everything should be a class. But Java is also a general purpose pragmatic language which calls for efficiency so the primitives were included.
So we're left with a need to bridge the gap between the primitives and classes and the wrapper classes is such an attempt. Another is the introduction of so called autoboxing in the new version of Java. It allows for automatic conversion between primitives and the corresponding wrappers.
Use primitives for speed and their wrappers for OO. Avoid conversions because they're costly even if hidden as a result of autoboxing.
uj_a at 2007-7-8 0:56:12 >

Thanks... i was used this type of declaration just for this example.... wrapping classes !!! was my doubt .. and need of that..
Use primitives for speed and their wrappers for OO. Avoid conversions because they're costly even if hidden as a result of autoboxing !!1
About wrapper class issue. As mentioned it is just inheritance. It then becomes a wrapper for JButton if you really let you class contain another instance of JButton (composition). And depending on your purpose of using the wrapper, you can have other name for your patterns (decorator, proxy, adapter,...)
I think you can search for wrapper pattern to read more if you wish to:
google search: Design pattern wrapper
Yep, I'm sure that your naming example is just for fun and for example. I think it would be great if we have a site that introduces funny code. I always get excited when reading funny code, weird naming, etc... It is really interesting of someone shows me this kind of site.
Happy coding :))
Happy coding makes the site to funny !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
> > Roast in hell for giving variables names like this.> ;)> > We can make it worse .. JavaPerl :)I thought that was a myth perpepuated by a Dr Dobbs article a number of years ago?