Java technology improvement, review, and summary (2)

Source: Internet
Author: User

Java technology improvement, review, and summary (2)

Next reflection:

Array reflection, also see the code comprehension:

int [] a1 = new int[]{1,2,3};int [] a2 = new int[4];int[][] a3 = new int[2][3];String [] a4 = new String[]{"a","b","c"};System.out.println(a1.getClass() == a2.getClass());System.out.println(a1.getClass() == a4.getClass());System.out.println(a1.getClass() == a3.getClass());System.out.println(a1.getClass().getName());System.out.println(a1.getClass().getSuperclass().getName());System.out.println(a4.getClass().getSuperclass().getName());Object aObj1 = a1;Object aObj2 = a4;//Object[] aObj3 = a1;Object[] aObj4 = a3;Object[] aObj5 = a4;System.out.println(a1);System.out.println(a4);System.out.println(Arrays.asList(a1));System.out.println(Arrays.asList(a4));printObject(a4);printObject("xyz");

Private static void printObject (Object obj) {Class clazz = obj. getClass (); if (clazz. isArray () {int len = Array. getLength (obj); for (int I = 0; I
 
  

4: ArrayList and HashSet

                Collection collections = new HashSet();ReflectPoint pt1 = new ReflectPoint(3,3);ReflectPoint pt2 = new ReflectPoint(5,5);ReflectPoint pt3 = new ReflectPoint(3,3);collections.add(pt1);collections.add(pt2);collections.add(pt3);collections.add(pt1);
              System.out.println(collections.size());
      public class ReflectPoint {private int x;public int y;

public ReflectPoint(int x, int y) {super();this.x = x;this.y = y;}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + x;result = prime * result + y;return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;final ReflectPoint other = (ReflectPoint) obj;if (x != other.x)return false;if (y != other.y)return false;return true;}}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.