Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help,help,help

 
feng lee
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"unary + has no effect on the value of its operand,byt the expression is promoted to at least int."-----from Complete Java2 Certification
Study Guide.That means -1 will be promoted at least int type.so "byte i=-1;"will results in compile error.But when I comile it,it runs well.Why?
 
Keen Chen
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because -1 is a literal,
not a var

if RHS is a compile-time constant, and in the range of the LHS, the assignment is accepted by jvm
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic