java - autoboxing and generics -


I'm really confused on both topics, someone can explain to me

  & Lt; Long & gt; Query parasomes = new arrelisted & lt; Long & gt; ();  
  1. Is the above mentioned a generic or autoboxing and what is unboxing?
  2. Is this a best practice?
  3. Some people say that autoboxing
  4. If I use normal, can I avoid autoboxing and unboxing?
    1. The above generic example is automatic boxing automatic conversion Will be, by the compiler, in a cover type a primitive type, and vice versa. In your case, for example, from long one of the long variables:

        long para = 13 L; QueryParms.add (ultimate);  
    2. Using generic? Yes. This allows you to specify what will be included in your list. You should use them. Using Auto-Boxing? Yes, this simplifies the code, and you do not have to worry about the conversions in the recurring variable (and vice versa) between the recurring variable types.

    3. There is no auto-boxing evil (IMHO) in some corner cases where auto boxing can be very upset, but if you know how it works, You should not have to worry about it. If you need to know more about it, then here it is mentioned.

    4. If you want to create a list in which the wrapper (in your case, long ), you have to deal typing conversions, you can use a clear type of conversion Or you can use automatic boxing.


Comments