当前位置:网站首页>The difference between objects and objects
The difference between objects and objects
2022-07-04 00:19:00 【Hello】
One 、Object class
If a class does not specify a parent class , Default is inheritance Object class .Object Common in class 11 A way : Often used equals(),toString() Are directly used or rewritten Object These methods in it ; And then there is final native The method of decoration : Reflection requires getClass(), Required for thread operation notify(),notifyAll(),wait(long timeout); also native The method of decoration :hashCode() and clone()
Source code :
package java.lang;
public class Object {
private static native void registerNatives();
static {
registerNatives();
}
public final native Class<?> getClass();
public native int hashCode();
public boolean equals(Object obj) {
return (this == obj);
}
protected native Object clone() throws CloneNotSupportedException;
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
public final native void notify();
public final native void notifyAll();
public final native void wait(long timeout) throws InterruptedException;
public final void wait(long timeout, int nanos) throws InterruptedException {
if (timeout < 0) {
throw new IllegalArgumentException("timeout value is negative");
}
if (nanos < 0 || nanos > 999999) {
throw new IllegalArgumentException(
"nanosecond timeout value out of range");
}
if (nanos > 0) {
timeout++;
}
wait(timeout);
}
public final void wait() throws InterruptedException {
wait(0);
}
protected void finalize() throws Throwable {
}
}
Two 、Objects class
Objects Class is final Modified class , Non inheritable , Internal methods are static Method , from jdk1.7 It was introduced at the beginning Objects class .
Source code :
package java.util;
import java.util.function.Supplier;
public final class Objects {
private Objects() {
throw new AssertionError("No java.util.Objects instances for you!");
}
public static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
}
public static boolean deepEquals(Object a, Object b) {
if (a == b)
return true;
else if (a == null || b == null)
return false;
else
return Arrays.deepEquals0(a, b);
}
public static int hashCode(Object o) {
return o != null ? o.hashCode() : 0;
}
public static int hash(Object... values) {
return Arrays.hashCode(values);
}
public static String toString(Object o) {
return String.valueOf(o);
}
public static String toString(Object o, String nullDefault) {
return (o != null) ? o.toString() : nullDefault;
}
public static <T> int compare(T a, T b, Comparator<? super T> c) {
return (a == b) ? 0 : c.compare(a, b);
}
public static <T> T requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}
public static <T> T requireNonNull(T obj, String message) {
if (obj == null)
throw new NullPointerException(message);
return obj;
}
public static boolean isNull(Object obj) {
return obj == null;
}
public static boolean nonNull(Object obj) {
return obj != null;
}
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) {
if (obj == null)
throw new NullPointerException(messageSupplier.get());
return obj;
}
}
边栏推荐
- 2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
- Sword finger offer day 4 (Sword finger offer 03. duplicate numbers in the array, sword finger offer 53 - I. find the number I in the sorted array, and the missing numbers in sword finger offer 53 - ii
- [NLP] text classification still stays at Bert? Duality is too strong than learning framework
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- P1656 bombing Railway
- Is the low commission link on the internet safe? How to open an account for China Merchants Securities?
- NLP pre training technology development
- Actual combat | use composite material 3 in application
- Alibaba cloud container service differentiation SLO hybrid technology practice
- AI Challenger 2018 text mining competition related solutions and code summary
猜你喜欢
Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
The first game of the new year, many bug awards submitted
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
Analysis of refrigeration and air conditioning equipment operation in 2022 and examination question bank of refrigeration and air conditioning equipment operation
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Deep learning ----- using NN, CNN, RNN neural network to realize MNIST data set processing
Tencent interview: can you find the number of 1 in binary?
The interviewer's biggest lie to deceive you, bypassing three years of less struggle
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
How to write a good title of 10w+?
随机推荐
Iclr2022: how does AI recognize "things I haven't seen"?
Selenium check box
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
Axure resources and prototype tool Axure RP 9 download
[Mongodb] 2. Use mongodb --------- use compass
Detailed explanation of the relationship between Zhongtai, wechat and DDD
Alibaba cloud container service differentiation SLO hybrid technology practice
No qualifying bean of type ‘com. netflix. discovery. AbstractDiscoveryClientOptionalArgs<?>‘ available
After the Lunar New Year and a half
Alibaba cloud container service differentiation SLO hybrid technology practice
1214 print diamond
What is the potential of pocket network, which is favored by well-known investors?
Suggestions for improving code quality
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Is user authentication really simple
IO flow principle and classification
Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
2022 free examination questions for hoisting machinery command and hoisting machinery command theory examination
D24:divisor and multiple (divisor and multiple, translation + solution)
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) simulated examination and Guangdong Provincial Safety Officer a certificate third batch (main person in charg