How to add two classes to same .java file without nesting?

119 views Asked by At

Result:

public class cls1 
{
    short f1;

    short f2;

    byte f3;

  }

  public class cls2 
{
    short f4;

    short f5;

    byte f6;

  }

Result not like this :

public class cls1 
{
    short f1;

    short f2;

    byte f3;

  public class cls2 
{
    short f4;

    short f5;

    byte f6;

  }
}
2

There are 2 answers

2
Jesse Wilson On

JavaPoet deliberately doesn’t support this. We recommend you use nesting or separate files instead.

1
FazoM On

In Java you can have multiple top level classes in single .java file, but only one of them can be public.