Skip to content

Commit 5f27b66

Browse files
committed
feat(WithoutLambdaExpression): add Employee interface with SoftwareEngineer implementation
What - Added Employee interface in package WithoutLambdaExpression with single method getName(). - Added SoftwareEngineer class implementing Employee: - Overrides getName() to return "Software Engineer". - Added Main class demonstrating usage: - Creates Employee reference pointing to new SoftwareEngineer(). - Prints result of getName(). Why - Shows traditional approach of implementing functional interfaces without lambdas. - Provides contrast with lambda-based example in HowUseLambda package. - Demonstrates how interface references can hold class instances implementing behavior. How - Declared Employee interface with getName() signature. - Implemented getName() in SoftwareEngineer to return fixed string. - In Main, created new SoftwareEngineer instance assigned to Employee reference. - Printed output of getName(). Logic - Inputs: none (hardcoded return value). - Outputs: "Software Engineer" printed to stdout. - Flow: 1. Instantiate SoftwareEngineer via new SoftwareEngineer(). 2. Assign to Employee reference E. 3. Call E.getName() → "Software Engineer". 4. Print result. - Edge cases handled: - Implementation ensures non-null string returned. - No risk of NullPointerException. - Complexity / performance: trivial O(1) operations. - Concurrency / thread-safety: - Class is stateless; safe for multi-threaded execution. - Error handling: - No exceptions expected. Real-life applications - Common design pattern where interfaces define contracts and concrete classes implement them. - Useful for decoupling higher-level logic from specific implementations. - Pre-Java-8 approach before functional programming and lambdas were available. - Demonstrates polymorphism basics for beginners. Notes - SoftwareEngineer.main() is currently unused; can be removed or used for testing. - Code can be simplified with lambdas (as shown in HowUseLambda), but this example illustrates explicit class implementation. - Annotating Employee with @FunctionalInterface would clarify its intended role, though not required here. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent 7fa7b79 commit 5f27b66

File tree

1 file changed

+5
-0
lines changed
  • Java 8 Crash Course/Lambda Expression/src/WithoutLambdaExpression

1 file changed

+5
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package WithoutLambdaExpression;
2+
3+
public interface Employee {
4+
String getName();
5+
}

0 commit comments

Comments
 (0)