### What is this PR for?
This PR refactors the `StaticRepl` class to improve readability, maintainability, and align with modern Java best practices.
There are no functional changes.
- Generic type refinement with diamond operator in loop: Adds type safety by explicitly specifying the generic type. Prevents unchecked warnings and makes the code clearer to readers and tools.
- Replace `Arrays.asList` to `List.of` : List.of (Java 9+) produces an immutable list, which is safer and better communicates the intent that the list will not be modified. It avoids side effects of Arrays.asList, which is fixed-size and backed by the original array.
- Minor typos fixed: Corrected spelling mistakes and adjusted comments.
- Removes redundant boolean comparison to follow standard Java coding conventions.
- Replace index-based loop with enhanced for-each to eliminate boilerplate index management, improves readability, and reduces chances of off-by-one errors. It makes the intent ("iterate all elements") clearer.
- Variable declaration moved closer to usage to improve code locality and readability by reducing variable scope. This makes the code easier to maintain and follow.
### What type of PR is it?
Refactoring
### Todos
* [ ] - Task
### What is the Jira issue?
* [ZEPPELIN-6299](https://issues.apache.org/jira/browse/ZEPPELIN-6299)
### How should this be tested?
* Run existing unit tests to confirm behavior remains unchanged.
### Screenshots (if appropriate)
### Questions:
* Does the license files need to update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Closes #5048 from eunhwa99/ZEPPELIN-6299.
Signed-off-by: ParkGyeongTae <gyeongtae@apache.org>
|
||
|---|---|---|
| .. | ||
| src | ||
| pom.xml | ||
| README.md | ||
Overview
Java interpreter for Apache Zeppelin
Architecture
Current interpreter implementation supports the static REPL. It compiles the code in memory, execute it and redirect the output to Zeppelin.
Technical overview
-
Upon starting an interpreter, an instance of
JavaCompileris created. -
When the user runs commands with java, the
JavaParsergo through the code to get a class that contains the main method. -
Then it replaces the class name with random class name to avoid overriding while compilation. It creates new out & err stream to get the data in new stream instead of the console, to redirect output to Zeppelin.
-
If there is any error during compilation, it can catch and redirect to Zeppelin.
-
JavaInterpreterUtilscontains useful methods to print out Java collections and leverage Zeppelin's built in visualization.