java - Why compiler tries to Wide and Box Why not Box and Wide? -


When applying a special method, I have read that the Wide and the Box is Preferred, why not Box and Wide Why can you explain with a small example? Widening: calling a method with a narrow parameter type

 

public class test {static zero doIt (long L) {} public static zero main (string [] args) {int i = 1; Chhandam (i); // OK: Int I has been widened}}

Boxing: A method is calling that takes cover type with an ancient argument. Public class test {static zero doIt (integer i) {} public static zero main (string [] args) {int i = 1; Chhandam (i); // OK: integer I is boxed in the integer}}

wide and then boxing: does not work Public class exams {static zero doIt (long el) {} public static zero main (string [] args) {int i = 1; Chhandam (i); // Failures

Boxing and then wide: only works if a supertype to widen. Public class test {static zero doIt} {} static zero go (long L) {} public static zero main (string [] args) {int i = 1; Chhandam (i); // Fine. I have boxed for integer, and the number is a supertype of (i) of integer; // Fail: there is no supertype for long integer}}


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -