• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

(Long and Int )Incompatible types??

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Te
{
public static void main(String[] args)
{
System.out.println("Hello World!");
long l2[][][]=new int[2][2][2];// line 1
int i;
long a= i;//line 2
}
}

It gives error to line 1 as incompatible types...
why implicit cast is not performed???
But
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why implicit cast is not performed???



How do you implicit cast an int array to a long array? Neither is a subclass of the other.

In your example, how do you implicit cast an array of array of array of int to an array of array of array of longs? Again, neither is a subclass of the other.

Henry
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Implicit cast works if you are assigning int to a long (primitives). In your case you are trying to assign an 3d int array object to a 3d long array object reference. It would have worked if int was a subclass of long but i guess it not.
 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Long and Integer are subclasses of Number class. So they are not related to each other, in other words, you cannot cast a Long array to an Int array.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gitesh Ramchandani:
Long and Integer are subclasses of Number class. So they are not related to each other, in other words, you cannot cast a Long array to an Int array.



Actually, this has nothing to do with the Long and Integer classes -- we are discussing int and long (primative).

int arrays and long arrays are objects, even though their elements are not. And they both subclass from the Object class.

Henry
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
eggjactly
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Henry Wong:


Actually, this has nothing to do with the Long and Integer classes -- we are discussing int and long (primative).

int arrays and long arrays are objects, even though their elements are not. And they both subclass from the Object class.

Henry



Opps!! i was half-sleepy when i replied...Sorry.

 
money grubbing section goes here:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic