Fork me on GitHub
#java
<
2023-01-06
>
Adam Helins11:01:37

It's been years since I've done some proper Java so I'm rusted... I'm trying to subclass using gen-class . The Parent has only private CTORs and exposes a public static create method. Using the subclassed Child, I can indeed do (Child/create ...). However, no matter what I do, I always get a Parent back, whereas I obviously want a Child. Any pointers? :thinking_face: 🙏

jumar12:01:51

https://stackoverflow.com/a/3952820/1184752 to make a subclass of a class with only private constructors?

Adam Helins12:01:43

Ah, fair point. Do you know what would happen if the CTORs where public/protected? Since the return type of create , which delegates to the CTORs, is Parent

Adam Helins17:01:30

Yes so I hit a bottleneck I believe. It seems you can subclass but the static method is (I believe) attached to the Parent .

emccue00:01:06

You cannot subclass something with only private constructors 🤷

emccue00:01:16

since you need to call super()

emccue00:01:30

and super needs to match to a constructor you have access to