Java Reference
In-Depth Information
body of the conditional with the
else
block (or the code following the con-
ditional). The resulting operation is logically equivalent.
Remove redundant
cast
—Removes a cast that is unnecessary because the
cast value is already of the correct type.
■
Add type cast
—Casts a reference to the expected type as allowed to sat-
isfy the conditions. For example, if you're pulling a
String
from a collec-
tion and assigning it to a local variable,
IDEA
casts the value from an
object to a
String
.
■
3.9 Continuing the ACME project
If you want to use this command-line interface, to test the system if for no other
reason, you'll need a
CurrencyService
against which to test. That's where the bulk
of the functionality lies; all the program will do, ultimately, is provide a facility to
call that service and provide the results through an effective user-interface. Let's
mock up a false service called
FixedRateCurrencyExchangeService
in the
com.
acme.conversion.currency.service
package. Follow these steps:
Using the
Project
tool window, right-click the service package and use
New | Class
(
Alt+Insert
), naming the class
FixedRateCurrencyExchange-
Service
.
1
Make this class implement the
CurrencyExchangeService
interface by
modifying the class declaration to include the
implements Currency-
ExchangeService
clause (don't forget, you can use Class Name Comple-
tion [
Ctrl+Alt+Space
] to fill this name in for you). As soon as you do,
IDEA
marks the class declaration with a red wavy underline, indicating an
error (there's also a red marker in the marker bar). Hovering your mouse
over the offending code tells you that your class doesn't implement the
interface it claims to. Of course it doesn't—you haven't implemented the
methods yet.
2
Rather than looking for the
CurrencyExchangeService
interface, activate
the
Code | Implement Methods
option (
Ctrl+I
). The ensuing dialog
shows a very small tree: Your class is implementing one interface, and
that interface has but a single method defined. Select the method, and
click
OK
. You'll be returned to the editor. (Alternatively, you can press
Alt+Enter
on the wavy error, and
IDEA
will suggest solutions to the
error using intention actions, including
Implement methods
.) In any
case, the method is implemented for you automatically, and the error
3