This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Array initialization Problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array initialization Problem." Watch "Array initialization Problem." New topic
Author

Array initialization Problem.

Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44
This Code Compiles Fine

int[] g={ new Integer(4),new Short("6"),new Character('c')};

but i get a Compilation error When try to write

int[] g={ new Integer(4),new Short(6),new Character('c')};

Although two Short Constructors are perfectly Legal

Please help me.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you haven't used both valid constructors
Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44
But Short(String s), Short(short s) are Valid and that is what i did.

Constructor Summary
Short(short value)
Constructs a newly allocated Short object that represents the specified short value.
Short(String s)
Constructs a newly allocated Short object that represents the short value indicated by the String parameter.
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
ok, but i fear you invoked Short(int s)

Try to do the following and your code will compile:



Bye,
Nicola
Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44
Why inside an Array an implicit casting is Required which is not in case we initialize outside an Array
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
It's not a matter of arrays.

This code won't compile as well, and for the same reason.


Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44
Ya i got that.. Thanks a lot Nicola...
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
You are always welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array initialization Problem.
 
Similar Threads
Operator assigment question
Question on widening ,boxing
Wrappers
Collections
overloading example from examlab