Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Bear Bibeault
• Junilu Lacar
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• salvin francis
• Frits Walraven
Bartenders:
• Scott Selikoff
• Piet Souris
• Carey Brown

# Primitive

Greenhorn
Posts: 4
Hi. This is my first time here. It is really great!! It has solved a lot of questions of mine.Now I have one more question. Please help me.
I am always confused about the assignments between primitives.I don't know when the casting is required.Here is my understanding and my questions. Please correct and answer me.
double = int Yes
int = double No
float = double No
double = float ??
int = long No
long = int Yes
How about the case in method call? e.g. Method(int x, int y) can I call it like Method(double, double)? How about the reverse?
Thank you very much.

Greenhorn
Posts: 25
double = int Yes
int = double No
float = double No
double = float ??
int = long No
long = int Yes
Ok when you are doing assignment think in this terms. The smaller type will always fit into a larger one right ?
double = float yes you can.
also remember if you don't specify float f = 10.2f with an f it will be treated as a double literal.
Now about method call i didn't understand something. Do you mean if your method is designed to accept int values and you send it a double value what would happen ? It's a mistake to do this. And will result in an error. But if you pass to that method a short or a char they are going to be promoted to int values. I hope this helps.

 I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad: Thread Boost feature https://coderanch.com/t/674455/Thread-Boost-feature