aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implicit downcast possible?
 
Similar Threads
Modifiers for anonymous inner classes and static nested classes
Interface constants
what is the use of the page implicit variable
How do we get Servlet Init Parameter thru EL?
Implicit and Explicit Objects