• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Casting....???????

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Prim{
void Call(float f){
System.out.println(f);
}
}

class Scr{
public static void main(String[] argv){
long ty =67L;
new Prim().Call(ty);
}
}
/*When i ran above code it runs well .........? but WHY???
As i know there is Widening Conversion done explicitly.
When
1. Target type is wide enough.
2. Target and source is compitable
Am i right???

in my case source is long(64) and target if float(32) and it still widening .....?

also Why i cannot assign float value to long(without casting) but converse is true ?
Pls help me out......

Regards
Yogesh Sood(India)*/

//Another problem
byte b1=2*2;//1
byte b2=2;//2
b2*=2;//3
/*why line 1 result in error i know that expression is promoted to int and to
do Narrowing conversion u have to do Explicit Casting....
Am i right.....
but what happen to line 3 is it the expression is not promoted to int.......?
pls help me out;
Regards
Yogesh Sood(India)
*/
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yogesh,
Yes, long to float is a widening conversion even hence explicit casting is not required. Refer to JLS here:
http://java.sun.com/docs/books/jls/second_edition/html/conversions.doc.html#25214
Regards,
Milind
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic