What patterns make people suspect Java code was generated by AI? Are any of them reliable enough to use when evaluating code?
Can you actually tell if Java code was AI-generated?
Answers
Not reliably from the code alone. Extra comments, no comments, big methods, awkward class structures and huge commits have all been offered as clues, but people wrote code like that long before current AI tools.
Those things can be useful review prompts. They aren't proof of authorship, and some even point in opposite directions. I'd be wary of rejecting code or accusing someone based on style.
Reply to this answer
Look at whether comments are useful to the next reader. A comment that narrates an obvious method, repeats another comment, or describes a completed work plan can suggest the code wasn't cleaned up carefully.
That still doesn't tell you who wrote it. The actionable issue is that stale or redundant comments make maintenance harder, so ask for those to be fixed regardless of their origin.
Reply to this answer
Tests are worth reading, not just counting. A tiny change accompanied by a pile of repetitive tests might deserve a closer look. So might tests that capture exact log messages instead of checking the behavior the code promises.
But lots of tests can be entirely reasonable, and generated code doesn't necessarily come with tests at all. Check what the tests cover and whether they would catch a meaningful regression.
Reply to this answer
There are some Java-specific quirks people notice, like fully qualified type names where imports would be clearer, unnecessary nesting around try-with-resources, or a proliferation of resolver classes. None of those is an AI fingerprint.
Judge each choice in context. A defensive copy in a record constructor, for example, might look excessive at first but can protect against later changes to a mutable collection.
Reply to this answer
I'd focus on whether the author can explain the design and whether the change works. Review the implementation, run the tests, and ask about surprising choices. A short history with one enormous commit can make review harder, but it doesn't establish how the code was produced.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions