https://javarush.com/groups/posts/1949-znakomstvo-s-klassami-napisanie-sobstvennihkh-klassov-konstruktorih
Не понимаю в чем ошибка и почему не хочет компилировать:
Error:(23, 39) java: incompatible types: possible lossy conversion from int to short.
Вроде как по логике все верно, даже и без переменных convert и со скобками перед height в операторе if.
public class User {
String name;
short age;
int height;
public User(String name, short age, int height){
this.name = name;
this.age = age;
this.height = height;
if (age>height) {
short convertHeight;
convertHeight = (short) height;
int convertAge;
convertAge = (int) age;
this.age = convertHeight;
this.height = convertAge;
}
}
public static void main(String[] args) {
User User1 = new User("Alex", 23, 181);
}
}