You are not passing two parameters. There is no way to pass more parameters than the accepted method. You are making a mathematical expression with two operands and passing the result as parameter. See this way:
FontFactory.getFont(FontFactory.defaultEncoding, 10, bold + underline)
This is not the same thing, but it shows with arithmetic exactly the same way you used in your example. Let’s consider that the variable bold
Valha, 1 and the underline
worth 2, then you will be passing 3 to the third parameters of this method, only this.
You probably just met the logical operator |
called "OR LOGICAL" described in boolean algebra.
This is a simple way to manipulate bits. You can connect all the bits required in an operation. The expected parameters is a byte or sequence of bytes which represent several logical states. Each state is a single bit which obviously can be turned on or off. If you search this enumeration com.lowagie.text.Font
will see that its values are exponential (0, 1, 2, 4, 8, 16). And the logical OR is only saying to link these values. At the bottom is a sum. If, for example, the BOLD vale 2 e o
UNDERLINE` is worth 4, the logical OR will ensure that these bits are connected, resulting in 6.
I will not extend myself in these details of the calculation, this the hugomg answer already explains and the AP posted a link in comment (Using Bit Flags and Enumsets in Java). The important thing for your question is that the operator |
does not accept more than one parameter (actually the correct name is argument since you are passing, parameter is what you receive), it is only doing a calculation before sending. Another way of seeing:
int config = com.lowagie.text.Font.BOLD | com.lowagie.text.Font.UNDERLINE;
FontFactory.getFont(FontFactory.defaultEncoding, 10, config);
It is clear that there are only three parameters.
You can read more about the operator in that reply.
A doubt that remained, would be the following, this is done by
JMV
, because I’m imagining it at the level ofdebug
understands, as this appears on the console for example fromEclipse
, would be shown bothenuns
, or show theenum
of this sum.– Macario1983
If you’re talking about the end result, there’s no way to show both
enums
more. Remember the first example I gave. If it was a sum, would it show "Bold + underline"? No, it would show the result of this account. With theenum
will happen the same. These twoenums
are constants with a certain value. They are not magic constructions of language. After you run some math on them, only the result remains. The other side, ie the method that is receiving this result, should know how to manipulate this information.– Maniero
To complement I am posting this blog http://eddmann.com/posts/using-bit-flags-and-enumsets-in-java/
– Macario1983