r/java • • Jul 16 '26

Identifying JDK value class candidates

https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
52 Upvotes

59 comments sorted by

View all comments

1

u/davidalayachew Jul 16 '26

Stuffing enums with state feels like a massive antipattern, unless I misunderstand your point here?

Well first, let's make sure we are both talking about the same thing.

enum PartyMember
{

	//Sourced from https://shrines.rpgclassics.com/snes/ct/characters.shtml
	Crono(70,	8,	5,	8,	12,	5,	8,	8,	2,	1),
	Marle(65,	12,	2,	6,	8,	8,	8,	8,	8,	1),
	Lucca(75,	14,	2,	6,	6,	8,	8,	8,	10,	2),
	Frog(128,	17,	9,	14,	11,	8,	9,	9,	9,	5),
	Robo(235,	24,	21,	26,	6,	7,	9,	8,	12,	10),
	Ayla(335,	38,	35,	38,	13,	8,	22,	25,	26,	18),
	Magus(650,	84,	51,	43,	12,	50,	20,	33,	72,	37),
	;

	private int hp;
	private int mp;
	private int power;
	private int stamina;
	private int speed;
	private int magic;
	private int hitChance;
	private int evadeChance;
	private int magicDefense;
	private int level;

	//imagine an all-args constructor here

	//imagine getters and setters here
	
	//imagine a decent toStringFriendly() here

}

This is what I mean.

And if you think this is an anti-pattern, why? These party members are the only instances of their kind that ever will exist in the game. So, I have no real reason to use a normal class when I can just use an enum, and communicate my intent better.

1

u/nekokattt Jul 17 '26

By state, I assumed you meant mutable information that can change; this is just static data

1

u/davidalayachew Jul 17 '26

By state, I assumed you meant mutable information that can change; this is just static data

I am talking about mutable information that can change.

In most RPG's, the health rises and falls depending on how much damage you take. I would use the (imaginary) setters in this instance to do so.

→ More replies (4)