Why can't I implicitly convert a double to an int?
问题 You can implicitly convert an int to a double: double x = 5; You can explicitly convert an int to a double: double x = (double) 5; You can explicitly convert a double to an int: int x = (int) 5.0; Why can't you implicitly convert a double to an int? : int x = 5.0; 回答1: The range of double is wider than int . That's why you need explicit cast. Because of the same reason you can't implicitly cast from long to int : long l = 234; int x = l; // error 回答2: Implicit casting is only available when