This is the desired result if any of the following conditions are met:Each instance of a class is inherently unique.Does not care if the class provides a "logical equality" test function.The superclass has overridden equals, and the behavior inherited from the superclass is also appropriate for subclasses.Class is private or package-level private, it can be determined that its Equals method is never called.If a class has its own unique "Roggi" concept (unlike the concept of object equivalence),
Why avoid creating unnecessary objects? The process of creating objects is still more cost-intensive, according to the performance tests given in the book, the time consuming to recreate objects is 250 times times the time consumed by reusing objects. The following is a list of scenarios where objects can be reused.1, String type Note that there is a big difference between string s = "as" and string s = new String ("as"), and the second method of creating a string instance will actually produce
(inkfish original, reprint please indicate the source: http://blog.csdn.net/inkfish/)
In order to seek the performance optimization of Java code, search from the internet to use final keyword compile-time inline optimization method, but really effective. The actual test found that not necessarily, even the performance impact of the huge, eventually abandoned the idea of using final optimization.
Test enviro
Recently in the watercress to see some book reviews, very feel, and there is a call effective Java is said to be very good, download a look, really masterpiece, a lot of things are not read, the skill is still shallow, still have to continue efforts. It feels so good to read that it's much better than a grammar-telling book.
The first part of the object is created and destroyed.
Said 5 principles.
1. Rep
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the
Today just began to read effective Java, the Chinese version of the reading is very awkward, but feel a lot of harvest.In addition, the content of this book is for Java 1.5 and 1.6.Here's the 2nd Chapter: Creating and destroying the contents of an object.First: Consider replacing the constructor with a static factory methodThis article is intended for scenarios w
"Effective Java" catalog excerpt.I know it looks bad. In the present, the lack of actual operation, can only temporarily extract the directory. With the increase in practice, fill in more examples slowly.Chapter 2 Creating and destroying Objects
Consider static factory methods instead of constructors
Consider a builder when faced with many constructor parameters
Enforce the Singleton proper
Before reading this book "Effective Java (second edition)" is very early. This book is indeed a good book. You need to chew slowly and have a different experience every time you look.Write a blog here to consolidate.Chapter I. Creating and Destroying objects Consider replacing the constructor with a static factory methodUsually we get an instance of the class, and the more frequently used method is to use t
corresponding domain name queue, send and update the last send time of the changed domain name.2. Unlock the domain to send records.In this way, the non-blocking queue is used for message queue, which improves the concurrency of the system.It seems to solve the problem, but it was blacklisted by some service providers.The system is then analyzed as follows:This is a typical producer-to-consumer issue in which Java client-produced messages are timed t
With the effective Java this book to see more and more, found in peacetime use of Java made a lot of obvious mistakes, they usually know a little but the lack of use is also more and more.As for enumeration classes, the suggestion in the book is to replace the traditional static constants with enumeration classes, usually, if a class of data is represented by a d
Create | objects
Effective Java Learning notes the Java language supports four basic types: interface (Interface), Class (Class), array (array), and primitive type (primitive). The first three types are often referred to as reference types (reference type), instances and arrays of classes are objects (object), and the values of primitive types are not objects. A
Tag: Is the CER object type call error arraylist conversion extend compilerToday will be effective Java (second edition) in the generic part of the reading, deep understanding of their own generic mastery of how unskilled, or need more practice.Say less nonsense, on the point of focus:1. Do not use prototypesLike what:New ArrayList ();When you use the list reference to point to other lists with generics, th
Leetcode Original question: (That is, to determine whether the binary tree is a two-fork search tree)Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node ' s key.
The right subtree of a node contains only nodes with keys greater than the node ' s key.
Both the left and right subtrees must also be binary search trees
The following
Calendar,date every time. Performance is improved in the following ways, and the meaning of the code is more clear.ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.TimeZone; Public classPerson {Private FinalDate birthday; Private Static FinalDate Boom_start; Private Static FinalDate Boom_end; Static{Calendar gmtcal= Calendar.getinstance (Timezone.gettimezone ("GMT")); Gmtcal.set (1946, Calendar.january, 1, 0, 0, 0); Boom_start=Gmtcal.gettime (); Gmtcal.set (1965, Calendar.january,
There are two ways to get an instance of a class:1. Provide a public constructor (most commonly used).2. Provide a public static factory method (static factory methods).// Static Factory Method Example Public Static Boolean ValueOf (boolean b) { return b? Boolean.TRUE:Boolean.FALSE;}Advantages of the Static factory approach:1. There is a name. When a class requires more than one constructor with the same signature (method signature = method name + parameter list), the static factory method
= servingsize; This. servings = servings; }/** * * @param val * Assign a value to an option * @return Builder object for chain adjustment Use the Assignment function * / PublicBuildercalories(intval) {calories = Val;return This; } PublicBuilderFat(intval) {fat = val;return This; } PublicBuilderSodium(intval) {sodium = Val;return This; } PublicBuilderCarbohydrate(intval) {carbohydrate = Val;return This; }/** * Create a Get object method and pass yourself (Builder) as a parameter * *
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.