This article mainly introduces the relevant information about the instances of this.getClass() and super.getClass() in java. Friends in need can refer to
Detailed explanation of this.getClass in java () and examples of super.getClass()
Preface:
Feelings when encountering the return values of this.getClass() and super.getClass() Doubts, suddenly became clear after exploration.
getClass() is a method of the Object class in java, and its prototype is:
##
public final Class<?> getClass()The return value is the Class object of the current runtime class.
##
package com.cyou.lijiang_hw; import java.lang.reflect.ParameterizedType; public class BaseDAO { public BaseDAO() { System.out.println("==============BaseDAO initialization============="); System.out.println("this.getClass() ---->" + this.getClass()); System.out.println("super.getClass()---->" + super.getClass()); } }
package com.cyou.lijiang_hw; public class UserDAO extends BaseDAO<User> { public UserDAO() { System.out.println("\n==============UserDAO initialization============="); System.out.println("this.getClass() ---->" + this.getClass()); System.out.println("super.getClass()---->" + super.getClass()); } }
package com.cyou.lijiang_hw; public class Test { public static void main(String[] args) { UserDAO userDAO = new UserDAO(); } }
==============BaseDAO<T> initialization============= this.getClass() ---->class com.cyou.lijiang_hw.UserDAO super.getClass()---->class com.cyou.lijiang_hw.UserDAO ==============UserDAO initialization============= this.getClass() ---->class com.cyou.lijiang_hw.UserDAO super.getClass()---->class com.cyou.lijiang_hw.UserDAO
The above is the detailed content of Cases about this.getClass() and super.getClass() in Java. For more information, please follow other related articles on the PHP Chinese website!