Skip to content

Commit ce4defa

Browse files
igor-suhorukovbeiwei30
authored andcommitted
Replace anonymous class with method reference (#2929)
* Replace anonymous class with method reference * Revert changes as per @beiwei30 code review
1 parent 0599f7d commit ce4defa

File tree

8 files changed

+8
-52
lines changed

8 files changed

+8
-52
lines changed

dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,7 @@ public void encode(Object obj, JSONWriter jb) throws IOException {
130130
GlobalEncoderMap.put(Date.class, e);
131131

132132
// init decoder map.
133-
Decoder d = new Decoder() {
134-
@Override
135-
public Object decode(Object jv) {
136-
return jv.toString();
137-
}
138-
};
133+
Decoder d = Object::toString;
139134
GlobalDecoderMap.put(String.class, d);
140135

141136
d = new Decoder() {

dubbo-common/src/test/java/org/apache/dubbo/common/concurrent/CompletableFutureTaskTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,7 @@ public void testListener() throws InterruptedException {
7878

7979
}, executor);
8080
final CountDownLatch countDownLatch = new CountDownLatch(1);
81-
completableFuture.thenRunAsync(new Runnable() {
82-
@Override
83-
public void run() {
84-
countDownLatch.countDown();
85-
}
86-
});
81+
completableFuture.thenRunAsync(countDownLatch::countDown);
8782
countDownLatch.await();
8883
}
8984

dubbo-common/src/test/java/org/apache/dubbo/common/concurrent/ExecutionListTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@ public void testAddRunnableToExecutor() {
5454
@Test
5555
public void testExecuteRunnableWithDefaultExecutor() throws InterruptedException {
5656
final CountDownLatch countDownLatch = new CountDownLatch(1);
57-
this.executionList.add(new Runnable() {
58-
@Override
59-
public void run() {
60-
countDownLatch.countDown();
61-
}
62-
}, null);
57+
this.executionList.add(countDownLatch::countDown, null);
6358

6459
this.executionList.execute();
6560
countDownLatch.await();

dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ protected Integer initialValue() throws Exception {
4949
};
5050

5151
for (int i = 0; i < THREADS; i++) {
52-
Thread t = new Thread(new Runnable() {
53-
@Override
54-
public void run() {
55-
internalThreadLocal.get();
56-
}
57-
});
52+
Thread t = new Thread(internalThreadLocal::get);
5853
t.start();
5954
}
6055

dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,7 @@ public synchronized void export() {
206206
}
207207

208208
if (delay != null && delay > 0) {
209-
delayExportExecutor.schedule(new Runnable() {
210-
@Override
211-
public void run() {
212-
doExport();
213-
}
214-
}, delay, TimeUnit.MILLISECONDS);
209+
delayExportExecutor.schedule(this::doExport, delay, TimeUnit.MILLISECONDS);
215210
} else {
216211
doExport();
217212
}

dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,7 @@ public List<URL> lookup(URL url) {
245245
}
246246
} else {
247247
final AtomicReference<List<URL>> reference = new AtomicReference<List<URL>>();
248-
NotifyListener listener = new NotifyListener() {
249-
@Override
250-
public void notify(List<URL> urls) {
251-
reference.set(urls);
252-
}
253-
};
248+
NotifyListener listener = reference::set;
254249
subscribe(url, listener); // Subscribe logic guarantees the first notify to return
255250
List<URL> urls = reference.get();
256251
if (urls != null && !urls.isEmpty()) {

dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/zkclient/ZkclientZookeeperClient.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,7 @@ public void doClose() {
114114

115115
@Override
116116
public IZkChildListener createTargetChildListener(String path, final ChildListener listener) {
117-
return new IZkChildListener() {
118-
@Override
119-
public void handleChildChange(String parentPath, List<String> currentChilds)
120-
throws Exception {
121-
listener.childChanged(parentPath, currentChilds);
122-
}
123-
};
117+
return listener::childChanged;
124118
}
125119

126120
@Override

dubbo-rpc/dubbo-rpc-rmi/src/main/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocol.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222
import org.apache.dubbo.rpc.RpcException;
2323
import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
2424

25-
import org.aopalliance.intercept.MethodInvocation;
2625
import org.springframework.remoting.RemoteAccessException;
2726
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
2827
import org.springframework.remoting.rmi.RmiServiceExporter;
29-
import org.springframework.remoting.support.RemoteInvocation;
30-
import org.springframework.remoting.support.RemoteInvocationFactory;
3128

3229
import java.io.IOException;
3330
import java.net.SocketTimeoutException;
@@ -80,12 +77,7 @@ protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcExc
8077
// RMI needs extra parameter since it uses customized remote invocation object
8178
if (url.getParameter(Constants.DUBBO_VERSION_KEY, Version.getProtocolVersion()).equals(Version.getProtocolVersion())) {
8279
// Check dubbo version on provider, this feature only support
83-
rmiProxyFactoryBean.setRemoteInvocationFactory(new RemoteInvocationFactory() {
84-
@Override
85-
public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
86-
return new RmiRemoteInvocation(methodInvocation);
87-
}
88-
});
80+
rmiProxyFactoryBean.setRemoteInvocationFactory(RmiRemoteInvocation::new);
8981
}
9082
rmiProxyFactoryBean.setServiceUrl(url.toIdentityString());
9183
rmiProxyFactoryBean.setServiceInterface(serviceType);

0 commit comments

Comments
 (0)