Defining a finite set of instances of a class to check against I have a Type class that will have many instances. I get the instances from a web service. The Type class has a code instance field that uniquely ids an instance:
@Data
@AllArgsConstructor
public class Type {

 private String code;

}

Ten of these instances identify a special type. I have several places where I need to check if a Type is one of these special types:
aType.equals(new Type(&quot;specialType1&quot;)) || aType.equals(new Type(&quot;specialType2&quot;)) ||...

In other places, I need to find where aType is not a special type. To centralize these specialized types and the check, I put it in the Type class as follows:
@Data
@AllArgsConstructor
public class Type {
 
  private static final List&lt;Type&gt; specialTypes = Arrays.asList(new Type(&quot;specialType1&quot;),...);
  private String code;

  public boolean isSpecialType() {
    return specialTypes.contains(this);
  }
}

Should specialTypes and the logic to compare a type to special types be in the Type class? Or would this type of logic be better in a service class? Should the special types be defined as enums?
Update
Type instances are created via use of open feign:
import org.springframework.cloud.openfeign.FeignClient;

@FeignClient(name=&quot;type-service&quot;)
public interface TypeClient {

   @GetMapping(&quot;/type&quot;)
   List&lt;Type&gt; getTypes();
}
First of all, as &quot;being special&quot; is obviously an attribute of your Type class, the check should go into the Type class, as you did, therefore always choose:
public class Type {
    ...
    public boolean isSpecial() {...}
}

over
aType.equals(new Type(&quot;specialType1&quot;)) || aType.equals(new Type(&quot;specialType2&quot;)) ||...

Regarding the implementation: I'm not too fond of creating a static collection to compare to. First of all, you search every time, then you use a relatively heavyweight equals method, which seems somewhat exaggerated to me, if the only distinction is a string passed in the constructor.
Personally, I'd use the underlying strings as a constant and determint the special flag in the constructor:
public class Type {
    private static final List&lt;String&gt; SPECIAL_CODES = Arrays.asList(&quot;this&quot;, &quot;that&quot;, &quot;whatever&quot;);
    private final String code;
    private final boolean special;

    public Type(String code) {
        this.code = code;
        this.special = SPECIAL_CODES.contains(code);
    }

    public boolean isSpecial() {
        return special;
    }
}

(Note that this change will not make a difference in runtime in real life, unless you check isSpecial() in a tight loop. It is more of a gut-feeling of being somewhat clearer.)