minor cleanup work
This commit is contained in:
parent
e2d30f5683
commit
3d564b081e
|
@ -1,4 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
|
||||
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
|
||||
|
@ -26,7 +27,7 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|||
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=error
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
|
@ -35,7 +36,7 @@ org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
|||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=error
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
|
@ -48,6 +49,7 @@ org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignor
|
|||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
|
||||
|
@ -68,6 +70,7 @@ org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
|||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error
|
||||
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||
|
@ -82,6 +85,7 @@ org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
|||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
|
@ -91,6 +95,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=
|
|||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -11,6 +11,7 @@ public class AdderImpl implements Adder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addWithConsumer(Consumer<Integer> f) {}
|
||||
public void addWithConsumer(Consumer<Integer> f) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,5 +5,6 @@ public interface Foo {
|
|||
|
||||
String method(String string);
|
||||
|
||||
default void defaultMethod() {}
|
||||
default void defaultMethod() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,34 +6,32 @@ public class UseFoo {
|
|||
|
||||
private String value = "Enclosing scope value";
|
||||
|
||||
public String add(String string, Foo foo) {
|
||||
public String add(final String string, final Foo foo) {
|
||||
return foo.method(string);
|
||||
}
|
||||
|
||||
public String addWithStandardFI(String string, Function<String, String> fn) {
|
||||
public String addWithStandardFI(final String string, final Function<String, String> fn) {
|
||||
return fn.apply(string);
|
||||
}
|
||||
|
||||
public String scopeExperiment() {
|
||||
Foo fooIC = new Foo() {
|
||||
final Foo fooIC = new Foo() {
|
||||
String value = "Inner class value";
|
||||
|
||||
@Override
|
||||
public String method(String string) {
|
||||
return this.value;
|
||||
public String method(final String string) {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
String resultIC = fooIC.method("");
|
||||
final String resultIC = fooIC.method("");
|
||||
|
||||
Foo fooLambda = parameter -> {
|
||||
String value = "Lambda value";
|
||||
final Foo fooLambda = parameter -> {
|
||||
final String value = "Lambda value";
|
||||
return this.value;
|
||||
};
|
||||
String resultLambda = fooLambda.method("");
|
||||
final String resultLambda = fooLambda.method("");
|
||||
|
||||
return "Results: resultIC = " + resultIC +
|
||||
", resultLambda = " + resultLambda;
|
||||
return "Results: resultIC = " + resultIC + ", resultLambda = " + resultLambda;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
package com.baeldung.java8;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.Foo;
|
||||
import com.baeldung.FooExtended;
|
||||
import com.baeldung.UseFoo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class Java8FunctionalInteracesLambdasTest {
|
||||
|
||||
|
@ -22,39 +23,35 @@ public class Java8FunctionalInteracesLambdasTest {
|
|||
|
||||
@Test
|
||||
public void functionalInterfaceInstantiation_whenReturnDefiniteString_thenCorrect() {
|
||||
|
||||
Foo foo = parameter -> parameter + "from lambda";
|
||||
String result = useFoo.add("Message ", foo);
|
||||
final Foo foo = parameter -> parameter + "from lambda";
|
||||
final String result = useFoo.add("Message ", foo);
|
||||
|
||||
assertEquals("Message from lambda", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void standardFIParameter_whenReturnDefiniteString_thenCorrect() {
|
||||
|
||||
Function<String, String> fn = parameter -> parameter + "from lambda";
|
||||
String result = useFoo.addWithStandardFI("Message ", fn);
|
||||
final Function<String, String> fn = parameter -> parameter + "from lambda";
|
||||
final String result = useFoo.addWithStandardFI("Message ", fn);
|
||||
|
||||
assertEquals("Message from lambda", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultMethodFromExtendedInterface_whenReturnDefiniteString_thenCorrect() {
|
||||
|
||||
FooExtended fooExtended = string -> string;
|
||||
String result = fooExtended.defaultMethod();
|
||||
final FooExtended fooExtended = string -> string;
|
||||
final String result = fooExtended.defaultMethod();
|
||||
|
||||
assertEquals("String from Bar", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambdaAndInnerClassInstantiation_whenReturnSameString_thenCorrect() {
|
||||
final Foo foo = parameter -> parameter + "from Foo";
|
||||
|
||||
Foo foo = parameter -> parameter + "from Foo";
|
||||
|
||||
Foo fooByIC = new Foo() {
|
||||
final Foo fooByIC = new Foo() {
|
||||
@Override
|
||||
public String method(String string) {
|
||||
public String method(final String string) {
|
||||
return string + "from Foo";
|
||||
}
|
||||
};
|
||||
|
@ -64,35 +61,32 @@ public class Java8FunctionalInteracesLambdasTest {
|
|||
|
||||
@Test
|
||||
public void accessVariablesFromDifferentScopes_whenReturnPredefinedString_thenCorrect() {
|
||||
|
||||
assertEquals("Results: resultIC = Inner class value, resultLambda = Enclosing scope value",
|
||||
useFoo.scopeExperiment());
|
||||
assertEquals("Results: resultIC = Inner class value, resultLambda = Enclosing scope value", useFoo.scopeExperiment());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shorteningLambdas_whenReturnEqualsResults_thenCorrect() {
|
||||
final Foo foo = parameter -> buildString(parameter);
|
||||
|
||||
Foo foo = parameter -> buildString(parameter);
|
||||
|
||||
Foo fooHuge = parameter -> { String result = "Something " + parameter;
|
||||
//many lines of code
|
||||
final Foo fooHuge = parameter -> {
|
||||
final String result = "Something " + parameter;
|
||||
// many lines of code
|
||||
return result;
|
||||
};
|
||||
|
||||
assertEquals(foo.method("Something"), fooHuge.method("Something"));
|
||||
}
|
||||
|
||||
private String buildString(String parameter) {
|
||||
String result = "Something " + parameter;
|
||||
//many lines of code
|
||||
private String buildString(final String parameter) {
|
||||
final String result = "Something " + parameter;
|
||||
// many lines of code
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mutatingOfEffectivelyFinalVariable_whenNotEquals_thenCorrect() {
|
||||
|
||||
int[] total = new int[1];
|
||||
Runnable r = () -> total[0]++;
|
||||
final int[] total = new int[1];
|
||||
final Runnable r = () -> total[0]++;
|
||||
r.run();
|
||||
|
||||
assertNotEquals(0, total[0]);
|
||||
|
|
|
@ -6,10 +6,10 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.java8.entity.Human;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.java8.entity.Human;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
|
|
Loading…
Reference in New Issue