[NEW BUG]: Small enhancement for Class.isAnonymousClass()

Christoph Dreis christoph.dreis at freenet.de
Thu Dec 1 07:41:13 UTC 2016


I'm currently getting familiar with the source code to eventually contribute
something more in the future. While doing so I noticed some smaller
enhancements where I don't know if they even justify a mail. Please let me
know how you handle such tiny improvements based on the following: 

One of the arguably small improvements was Class.isAnonymousClass() which
checks for emptiness with "".equals(getSimpleName()) instead of
getSimpleName().isEmpty() and I see no way of getSimpleName() returning null
(I might miss something though). Anyhow, the latter is slightly faster and a
bit more verbose:

MyBenchmark.testEmpty   thrpt   20  364479649,385 ± 5805392,007  ops/s
MyBenchmark.testEquals   thrpt   20  287935443,484 ± 2895104,850  ops/s  

Again - if this is too small please let me know and excuse the disturbance.


=========== PATCH ============
# User Christoph Dreis <christoph.dreis at freenet.de>
Small enhancement for Class.isAnonymousClass()

diff --git a/src/java.base/share/classes/java/lang/Class.java
--- a/src/java.base/share/classes/java/lang/Class.java
+++ b/src/java.base/share/classes/java/lang/Class.java
@@ -1596,7 +1596,7 @@
      * @since 1.5
     public boolean isAnonymousClass() {
-        return "".equals(getSimpleName());
+        return getSimpleName().isEmpty();

More information about the core-libs-dev mailing list