参考地址:http://www.cnblogs.com/o-andy-o/archive/2012/12/22/2829563.html
万物皆对象,Object是一切对象的父类,索然在创建类型的时候没有直接的申明,编译器会帮助做这件事件。有事我们需要重写一些方法:比如
@Override public int hashCode() { // TODO Auto-generated method stub return super.hashCode(); } @Override public boolean equals(Object obj) { // TODO Auto-generated method stub return super.equals(obj); } @Override public String toString() { // TODO Auto-generated method stub return super.toString(); }
而这些方法都是父类Object中的本地方法,包括提供的对象锁wait(),notify()等方法都是父类继承而来。
代码执行的结果相同,原因是啥呢
System.out.println("当前类的的类名:" + getClass().getName()); System.out.println("调用父类的类名:" + super.getClass().getName());
getClass()是从Object继承来的,此时返回的是 Object运行时的类,不然都返回java.lang.Object
代码2
System.out.println(getClass().getSuperclass().getName());
此时返回的是父类Class的类名java.lang.Class
代码3 一切类对象的父类都是Object
System.out.println(getClass().getSuperclass().getClass().getSuperclass().getName()); System.out.println(getClass().getSuperclass().getClass().getSuperclass().getClass() .getSuperclass().getClass().getSuperclass().getClass().getSuperclass().getName()); 输出的结果是:java.lang.Object
代码四,那Object的父类是啥呢?
System.out.println(Object.class.getSuperclass()); 输出的结果是null,应证了Object是一切对象的父类
参考运行代码:
public class TestClassGetName { public static void main(String args[]){ TestClassGetName t = new TestClassGetName(); t.getName(); } public void getName(){ System.out.println("当前类的的类名:" + getClass().getName()); System.out.println("调用父类的类名:" + super.getClass().getName()); System.out.println("获取父类的类名:" + getClass().getSuperclass().getName()); System.out.println("获取父类的类名:" + getClass().getSuperclass().getClass().getName()); System.out.println("所有类的父类都是Object:" + getClass().getSuperclass().getClass().getSuperclass().getName()); System.out.println("所有类的父类都是Object:" + getClass().getSuperclass().getClass().getSuperclass().getClass().getSuperclass().getClass().getSuperclass().getClass().getSuperclass().getClass().getSuperclass().getName()); System.out.println("获取object类的父类:" + Object.class.getSuperclass()); } }
相关推荐
final Class conmanClass = Class.forName(conman.getClass().getName()); final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService"); iConnectivityManagerField.setAccessible(true)...
Class stringClass = name.getClass(); System.out.println("getName: " + stringClass.getName()); System.out.println("isInterface: " + stringClass.isInterface()); System.out.println("isPrimitive: ...
private Logger logger = Logger.getLogger(this.getClass().getName()); public void processBusiness(){ try { logger.info("start to processing..."); //business logic here. System.out....
String obj=user.getClass().getName(); clazz=Class.forName(obj); Class[] inters=clazz.getInterfaces(); for (int i = 0; i < inters.length; i++) { System.out.println("实现的接口 :"+inters...
System.out.println(request.getParameter(propertyName).getClass().getName()); Object value = request.getParameter(propertyName); PropertyDescriptor pd = new PropertyDescriptor(property...
spring-spi List<Say> loadFactories = SpringFactoriesLoader.loadFactories(Say.class, TestCase.class.... System.out.println(say.getClass().getName()); System.out.println(say.sayHrello("张三")); }
通配符定义的变量主要用作引用,调用与参数化无关的方法,如果要调用与参数化相关的方法,那么必须在使用?通配符引用之前调用,否则就与java 5提供泛型的目的背道而驰了。 b..向下限定通配符: 正确:Vector...
Field[] fList = obj.getClass().getDeclaredFields(); for (Field field : fList) { String value = prop.getProperty(field.getName()); String typeName = field.getType().getTypeName(); System....
jexiletools-es jexiletools-es 蚀代码模板 $ {:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}私有最终Logger logger = LoggerFactory.getLogger(this.getClass()。getName());
chain.doFilter((ServletRequest) Proxy.newProxyInstance(CharFilter.class.getClassLoader(),request.getClass().getInterfaces(), new InvocationHandler(){ public Object invoke(Object proxy, Method ...
import java.util.ArrayList; import java.util.List; ... MongoCredential credential = MongoCredential.createScramSha... System.err.println( e.getClass().getName() + ": " + e.getMessage() ); } } }
// 将从Excel表格读取到的数据与配置文件筛选成可以插入到数据库的数据 public List, Object>> parseExcelData( List, String>> excelDataMap, Map, List<ExcelMap>> dbfield) { List, Object>> list = new ...
* 将文本信息与异常写入日志文件 */ private void log(Throwable e, String msg) { log.println(new Date() + ": " + msg); e.printStackTrace(log); } /** * 此内部类定义了一个连接池.它能够根据要求创建...
String getName() 获取全限定类名(全限定,包含包名) Class类中方法 String getSimpleName() 获取类名简称 Class类中方法 Package getPackage() 获取包名 Class类中方法 T newInstance() ...
所有业务逻辑类皆可调用该类 package com.parddu.dao; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.PreparedStatement; ...
System.out.println("Couldn't find " + getClass().getName() + "/" + name); e.printStackTrace(); } return icon; } /// FILE MENU Action openAction = new AbstractAction("Open...") { public void ...
FacesMessage.SEVERITY_FATAL, x.getClass().getName(), x .getMessage()); FacesContext.getCurrentInstance().addMessage(null, message); return null; } } } 参考文献:...
mybatis实战教程mybatis in action之五与spring3集成附源码 mybatis实战教程mybatis in action之六与Spring MVC 的集成 mybatis实战教程mybatis in action之七实现mybatis分页源码下载 mybatis实战教程mybatis in ...
数组类继 承自 Object 类(因为 new Object[0].getClass().getSuperClass()是 Object.class)。 可以获得数组所在类的 Class 对象和类名 Class imageArrayInstance = Image[].class; 而利用 imageArrayInstance....
QuartzFactory.me().startJobOnce(TimeUtils.me().toString(DateTime.now()), jobId, "stati", this.getClass().getSimpleName(), OrderDataJob.class, param); 12.shiro权限框架,基于数据库url配置过滤,...