wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes implicit downcast possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "implicit downcast possible?" Watch "implicit downcast possible?" New topic
Author

implicit downcast possible?

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
in the following code, the question is asked, what will be the output? The answer is a compile time error. But the thing is, i thought it was possible for some implicit downcasting to occur - in what situations?
public class Rand{
public static void main(String argv[]){
int iRand;
iRand = Math.random();
System.out.println(iRand);
}
}


giddee up
El Roy Cabildo
Greenhorn

Joined: Oct 19, 2002
Posts: 23
of course it would compile error because Math.random() returns double not int! Loss of precission and java wont allow you that
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
yo, very true elroy ... i guess i was just wondering whether there where any similar-yet-different situations ... where implicit downcasting might occur>?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
final int i = 5;
byte b = i;
In this case the "final" tells the compiler that i can't change and therefore it will always fit into a byte.
[ February 19, 2003: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
ah, that's right, thankyou!
 
jQuery in Action, 2nd edition
 
subject: implicit downcast possible?
 
Similar Threads
Implicit and Explicit Objects
what is the use of the page implicit variable
Modifiers for anonymous inner classes and static nested classes
How do we get Servlet Init Parameter thru EL?
Interface constants