A brief talk on Javase object-oriented (object class ToString) _java

Source: Internet
Author: User
Tags object object reflection

Each object has an address hash value in memory, and this hash value is hexadecimal

Calls the Hashcode () method of the Object object, returning the hash value of this object

Call the Integer.tohexstring () method to convert the hexadecimal

Call the object's ToString () method to get: Class name @ hash value

Usually we will make a copy of the ToString () method because the default does not mean much

The principle of implementation is the reflection of the class

When we create an object, a Xxx.class file is generated on the hard disk, and the JDK defines class classes to describe these class files

Call the Object object's GetClass () method to get the class object

Call the GetName () method of the class object to get the name of the class

public class Objectdemo {

  /**
   * @param args
   *
  /public static void main (string[] args) {
    Objectdemo od =new Objectdemo ();
    System.out.println (Od.tostring ());//Output objectdemo@26f04d94
    System.out.println (integer.tohexstring ( Od.hashcode ());//output 26f04d94
    
    //Reflection
    Class c=od.getclass ();
    System.out.println (C.getname () + "@" +integer.tohexstring (Od.hashcode ()));
  }

The above discussion of Javase object-oriented objects (object class ToString) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.