Type Casting
noun
say it: “TYPE kas-ting” /ˈtaɪp ˌkæstɪŋ/
Telling Java to treat a value as another type, such as turning a double into an int by writing (int) in front of it.
What is Type Casting in Java?
Type Casting — Explicitly converting a value to another compatible type.
class TicketCounter {
void convertValues() {
int tickets = 7;
double exactTickets = tickets;
int wholePrice = (int) 7.9;
}
}
In a sentence
- “Type casting 9.99 to an int gave me 9, because the part after the decimal point is dropped.”
Level: Novice · More Java terms at this level
Updated