3 ms·
One another example I encountered today. <Prompt> show me an example of an enum LifecycleStatus deriving from an abstract class Status with fields status_type
by rakejake 4y ago
One another example I encountered today.
<Prompt>
show me an example of an enum LifecycleStatus deriving from an abstract class Status with fields status_type String and reason String (with default getters). Use a lombok builder on the enum class and show an example of building a LifecycleStatus enum setting only the status_type.
</Prompt>
Answer: ChatGPT tells me it absolutely is possible, and generates the code as well. Except, java Enums cannot derive an abstract class (since they implicitly derive Enum<T>). You can only have an enum implement an interface. Here, I realised that I had not mentioned the word "java" in this prompt (though I had started off the chat with the word "java" so I assume it was in the context.
In any case, my next prompt was:
<Prompt>
Is the code example you shared for java?
</Prompt>
Answer: Yes, the code example I shared is for Java. Specifically, it is for Java 8 or newer, as it uses the @Builder annotation from Lombok, which was introduced in version 1.16.8 of Lombok.
I continued the conversation and had it try out other methods of achieving the same thing. (abstract class with static inner builder class, enums implementing an interface). But it basically follows your prompt and provides whatever you ask it to provide. When I asked it to have an enum derive an abstract class, it did that for me without any complaints. When I later said, this was not possible, it changed tracks.
I echo other users in saying that, I would not want to use this for learning anything new. There is no point if I have to break my flow and verify after every query. But it is a good rubber duck. The chat interface can be used as a deprocrastination tool - when you are not able to come up with anything fruitful, just ask a few questions. This gets the ball rolling at least.