Java 9 jshell features in which we can create class, methods for minor checking and testing of code without create any Java files and here are solution for modification or add method of class once class has  been created using jshell.

 

  1. Open cmd and Type jshell
  2. Create Class Demo in jshell
  3. public class Demo{
      public void method1(){
        System.out.println("This is first method.");
      }
    }

     

    Java 9 jshell class method

    Jshell Demo

  4. Now Type : /edit Demo
    – It will open below java editor:

    Java 9 jshell edit class method

    Demo Edit

     

  5. Do your updates and click on Accept. It will replace existing class.

 

References:

https://stackoverflow.com/questions/42428079/jshell-how-to-add-method-to-existing-class-without-replacing-this-class

 

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *