File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/main/java/org/codefx/demo/effective_java/_06_unnecessary_objects Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .codefx .demo .effective_java ._06_unnecessary_objects ;
2+
3+ import org .openjdk .jmh .annotations .Benchmark ;
4+ import org .openjdk .jmh .annotations .Param ;
5+
6+ import java .net .MalformedURLException ;
7+ import java .net .URL ;
8+
9+ public class UrlEquals extends ObjectCreationBenchmarks {
10+
11+ private String blog = "https://codefx.org" ;
12+
13+ private String youtube = "https://youtube.com/codefx" ;
14+
15+ @ Benchmark
16+ public boolean urlEqual () throws MalformedURLException {
17+ // NOTE unnecessary object:
18+ // There isn't anything unnecessary here. It's just that URL::equals
19+ // resolves the host name, which can take a while...
20+ return new URL (blog ).equals (new URL (youtube ));
21+ }
22+
23+ @ Benchmark
24+ public boolean stringEqual () throws MalformedURLException {
25+ return blog .equals (youtube );
26+ }
27+
28+ }
You can’t perform that action at this time.
0 commit comments