diff --git a/core-java-8/.settings/org.eclipse.jdt.core.prefs b/core-java-8/.settings/org.eclipse.jdt.core.prefs index c57289fc09..c38ccc1294 100644 --- a/core-java-8/.settings/org.eclipse.jdt.core.prefs +++ b/core-java-8/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/core-java-8/src/main/java/com/baeldung/AdderImpl.java b/core-java-8/src/main/java/com/baeldung/AdderImpl.java index 55cf84c378..5109f3aaba 100644 --- a/core-java-8/src/main/java/com/baeldung/AdderImpl.java +++ b/core-java-8/src/main/java/com/baeldung/AdderImpl.java @@ -6,11 +6,12 @@ import java.util.function.Function; public class AdderImpl implements Adder { @Override - public String addWithFunction(Function f) { + public String addWithFunction(Function f) { return f.apply("Something "); } @Override - public void addWithConsumer(Consumer f) {} + public void addWithConsumer(Consumer f) { + } } diff --git a/core-java-8/src/main/java/com/baeldung/Foo.java b/core-java-8/src/main/java/com/baeldung/Foo.java index c42ec86f8b..90ebdfeed3 100644 --- a/core-java-8/src/main/java/com/baeldung/Foo.java +++ b/core-java-8/src/main/java/com/baeldung/Foo.java @@ -5,5 +5,6 @@ public interface Foo { String method(String string); - default void defaultMethod() {} + default void defaultMethod() { + } } diff --git a/core-java-8/src/main/java/com/baeldung/UseFoo.java b/core-java-8/src/main/java/com/baeldung/UseFoo.java index bfa7a2f2c0..a91404ebaf 100644 --- a/core-java-8/src/main/java/com/baeldung/UseFoo.java +++ b/core-java-8/src/main/java/com/baeldung/UseFoo.java @@ -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 fn) { + public String addWithStandardFI(final String string, final Function 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; } - } diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasTest.java b/core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasTest.java index 0620ebd35a..94448fcc83 100644 --- a/core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasTest.java +++ b/core-java-8/src/test/java/com/baeldung/java8/Java8FunctionalInteracesLambdasTest.java @@ -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 fn = parameter -> parameter + "from lambda"; - String result = useFoo.addWithStandardFI("Message ", fn); + final Function 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]); diff --git a/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java b/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java index e0e10b293e..2ba9e417d6 100644 --- a/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java +++ b/core-java-8/src/test/java/com/baeldung/java8/Java8SortUnitTest.java @@ -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;