Oh okay. So it sounds like many languages, including Java, originally 
generated code where every message's type was placed into a single 
generated file (a file per .proto file). For Java, you can only have one 
public class per file, so the outer class technique was used so that it 
could be the single public class in the generated file, with each message's 
class as an inner class within the outer class.

But then some users wanted the option of splitting up the generated code, 
which let to the Java option to use multiple files, in which case there's 
no need for the outer class technique.

So the outer class technique wasn't to enable any specific Protobuf 
feature, it was just to work around the limitations of Java to make the 
code look like the code generated when using other languages.

On Monday, July 26, 2021 at 1:05:50 PM UTC-4 [email protected] wrote:

> Java protobufs originally only had the option to have the outer class, 
> which is consistent with some other languages' protocol buffers. We decided 
> to add the "multiple files" option for users to have the option. We 
> recommend using the multiple files option in most instances, but continue 
> providing both in case historic users are reliant on having the outer class 
> or if there are special cases in which a single file would be better.
>
> On Sunday, July 25, 2021 at 11:13:02 AM UTC-7 [email protected] wrote:
>
>> I googled this and found questions like "How to use Protobuf message as 
>> java class without a java outer class?" (
>> https://stackoverflow.com/questions/60312156/how-to-use-protobuf-message-as-java-class-without-a-java-outer-class)
>>  
>> which talk about how one might tweak their Protobuf Java code generation. 
>> For example, that person wants to avoid having outer classes. The answer 
>> tells them about the "multiple files" option.
>>
>> But I'd like to know why the Java generated code, by default, is split up 
>> this way. I didn't notice code split up like that when I used my same 
>> Protobuf files to generate Go code. I got just one struct per Protobuf 
>> message I defined. In Java, I get two classes per Protobuf message defined, 
>> and I can choose between them being nested or in separate files. Why?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/9b2a6b80-4668-4a56-bca4-cf31a9afc257n%40googlegroups.com.

Reply via email to