A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Array assignment
Olga Belova
Greenhorn
Joined: Apr 06, 2004
Posts: 3
posted
Apr 06, 2004 09:22:00
0
I just got confused with the whole array assignment deal. Can I assign integer array to a long array? I thought it is possible...
Abdulla Mamuwala
Ranch Hand
Joined: Jan 09, 2004
Posts: 225
posted
Apr 06, 2004 09:45:00
0
Please compile the following code,
class test{ public static void main(String args[]){ int i[]=new int[3]; long l[]=new long[3]; l=i; } }
The Output is:
C:\scratch\test.java:5: incompatible types
The above output is true for all primitive array types.
Olga Belova
Greenhorn
Joined: Apr 06, 2004
Posts: 3
posted
Apr 06, 2004 09:54:00
0
Thanks
Got you.
Gian Franco
blacksmith
Ranch Hand
Joined: Dec 16, 2003
Posts: 975
posted
Apr 06, 2004 13:10:00
0
Hi,
to complete the picture try:
public class ArrayTest { public static void main(String[] args) { String[] s1 = {"abc","def"}; Object[] o1 = new Object[3]; Integer[] i1 = {new Integer(10), new Integer(22)}; o1 = s1; o1 = i1; } }
this is allowed.
Greetings,
Gian Franco
"Eppur si muove!"
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Array assignment
Similar Threads
Array assignment
Arrays and Constructors
need help returning an array, got an error
operatots
HashMapping
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter