Преобразование типов

byte byteValue = 123;
short shortValue = byteValue ;
int intValue = shortValue ;
long longValue = intValue ;
char charValue = ’@’;
int intFromChar = charValue ;
long longFromChar = charValue ;
double doubleFromFloat = 1f;
float floatFromLong = longValue ;
double doubleFromInt = intValue ;

int intValue = 1024;
byte byteValue = ( byte ) intValue ;
double pi = 3.14;
int intFromDouble = ( int) pi;
float largeFloat = 1 e20f ;
int intFromLargeFloat = (int) largeFloat ;
double largeDouble = 1 e100 ;
float floatFromLargeDouble = ( float ) largeDouble ;

Арифметическое расширение

double doubleValue = 1d + 1f;
float floatValue = 1f * 1;
long longValue = 1L - ’0’;
byte a = 1;
byte b = 2;
byte c = ( byte ) (a + b);

Неявное приведение

byte a = 1;
a += 3;
// a = ( byte ) (a + 3);
byte b = -1;
b >>>= 7;
// b = ( byte ) (b >>> 7);

Оцените автора
Kosenkov.Pro
Добавить комментарий