zoukankan      html  css  js  c++  java
  • Object类

    一、Object类的作用和地位

         Object类的常用方法

        toString();

           toString方法可以将任何一个对象转换成 字符串返回,返回值的生成算法为:getClass().getName() + '@' + Integer.toHexString(hashCode())。

        equals();

          equals方法; Object类中的equals方法,用来比较两个引用的虚地址。当且仅当两个引用在物理上是同一个对象时,返回值为true,否则将返回false。

        hashCode();   

           获取对象的哈希码值,为16进制

        ……

    二、Object和Object[]之间的区别

        方法中的形参是Object类型时,任何类型的参数都可以传进去执行。

        方法中形参是Object[]类型时,只有对象数组可以传入执行。

    三、equals和==的区别

          equals方法 比较对象的虚地址,但是可以在类中被重写。

         如:String类重写了,两个相同值的String对象相比较为 true;

        String str=new String(“123”);

        String str1=new String(“123”);

        System.out.println(str.equals(str1));   打印为true.

      “==” 比较的是内存中的虚地址

        String str=new String(“123”);

        String str1=new String(“123”);

        System.out.println(str==str1);   打印为false

      

  • 相关阅读:
    openh264 动态调整码率
    ffmpeg的avcodec_encode_video2延迟
    深入浅出c++协程
    asio的异步与线程模型解析
    libco分析
    《深入理解kafka》阅读笔记
    记一次shm_open返回EINVAL的错误排查
    css 圆形脉冲动画
    animate.css VUE 使用
    python 装饰器
  • 原文地址:https://www.cnblogs.com/xuekai/p/7157251.html
Copyright © 2011-2022 走看看