Sorry for the horrendous question, don’t know how else to describe it,
I’m naturally a PHPer and i’m currently looking over some java and come across this section. The first line is just there for context, it is the line starting with QuotaKey that I’m interested in.
Key key = Keys.getKeyInstance( Keys.getKeyClass( cond.getKey( ) ) );
QuotaKey quotaKey = ( QuotaKey ) key;
Assuming that
QuotaKeyis a subclass ofKey, you are looking at a cast operator that converts a variable of the typeKeyto a variable of typeQuotaKey. You can write the same fragment more succinctly without a temporary variable:This operation checks for the
keyto be of the correct type before coercing its type to subclass, and causeClassCastExceptionon failures. It is a good idea to minimize the number of such casts in your program, because their validity cannot be reliably checked at compile time.