aspose file tools
The moose likes Beginning Java and the fly likes Do cast from int to short Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Do cast from int to short" Watch "Do cast from int to short" New topic
Author

Do cast from int to short

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Hi there, please could you see my code and tell me why I must also do cast of rangeDe5NumeroNoMaximo attribute
because that atributte also short typed...



thanks,
André AS
SP - Brazil


André AS
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#16021
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Hello to you David,

I joined your web link...

I read that the default value of long is 0L, ok but I can't use it right? Look at:



That shows compile-time error, why?


André AS
São Paulo - Brazil
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Should not that print their default value?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://java.sun.com/docs/books/jls/second_edition/html/defAssign.doc.html#25979
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

André Asantos wrote:Should not that print their default value?

Local variables inside methods, as you show in your example, do not have default values. You must initialize them to a value before you use them.

Only member variables (at the level of a class) are initialized with default values (0L in the case of a long).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do cast from int to short
 
Similar Threads
ID:3 SCJP Question of the day : Thursday June 10 2010
Ranch roundup game question
why compilation fails here
problem with javascript array and undefined values in Internet explorer
Multithreading problems in J2ME