Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of C# Enum Flags Attribute in Java?

Tags:

java

RE C# enums with the flag attribute:

http://dotnetperls.com/enum-flags

is there any way to get this behavior in Java?

like image 521
fred basset Avatar asked Jul 19 '10 19:07

fred basset


People also ask

What is equivalent to classes in C?

The closest thing you can get is a struct .

Is there pass in C?

Parameters in C functions There are two ways to pass parameters in C: Pass by Value, Pass by Reference.

Is there classes in C?

1. C Classes. A class consists of an instance type and a class object: An instance type is a struct containing variable members called instance variables and function members called instance methods.

What is pointer equivalent in Java?

Java doesn't have pointers; Java has references.


1 Answers

As long as you define your Enum values properly, you can use EnumSet to get that functionality.

RenderSet set = RenderSet.DataUri | RenderSet.GZip;

would become

EnumSet.of(RenderSet.DataUri, RenderSet.GZip);
like image 195
Justin Niessner Avatar answered Sep 26 '22 23:09

Justin Niessner