You are not passing two parameters. There is no way to pass more parameters than the accepted method. You are doing a mathematical expression with two operands and passing the result as a parameter. Here's how:
FontFactory.getFont(FontFactory.defaultEncoding, 10, bold + underline)
This is not the same thing, but shows with arithmetic the exact same shape you used in your example. Let's consider that the variable bold
is worth 1, and the underline
is worth 2, so you will be passing 3 to the third parameter of this method, only this.
You've probably just met the logical operator |
called " logical OR " described in Boolean algebra .
This is a simple way to manipulate bits . You can bind all the necessary bits in an operation. The expected parameters is a byte or sequence of bytes representing several logical states. Each state is a single bit that can obviously be turned on or off. If you search this enumeration com.lowagie.text.Font
you will see that its values are exponential (0, 1, 2, 4, 8, 16). And the logical OR is just saying to bind these values. In the background is a sum. If, for example, the BOLD vale 2 e o
UNDERLINE 'is 4, the logical OR will ensure that these bits are turned on, resulting in 6.
I will not go into this calculation details, this the hugomg answer already explains and the AP posted a comment link ( 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 to see:
int config = com.lowagie.text.Font.BOLD | com.lowagie.text.Font.UNDERLINE;
FontFactory.getFont(FontFactory.defaultEncoding, 10, config);
It is clear that it only has three parameters.
You can read more about the operator on this answer .