AndreaNobili
AndreaNobili

Reputation: 43077

What exactly do this variable that contains an inner class?

I have a doubt related to this variable that contains an inner class:

private final Action actionLogOut = new AbstractAction() {
    {
        putValue(Action.NAME, _("log-out"));
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        System.out.println("logOutButton clicked !!!");
        System.exit(0);
    }
};

My problem is that I can't understand what exactly do this line of code:

putValue(Action.NAME, _("log-out"));

Some one can help me?

Upvotes: 2

Views: 87

Answers (2)

codeMan
codeMan

Reputation: 5758

putValue() is a method with the 2 parameters and first parameter seems to be some sort of a constant, defined in either outer or inner class(I am assuming this since it is all Capital letters) and the second parameter

_("log-out")

is a function call to a function named ... something like this :

_(String arg1) // having _ as a function name is terribly a bad practice btw.

hence _("log-out") in the line putValue(Action.NAME, _("log-out")); will be substituted with the value that is returned from the function named _(String arg1)

Upvotes: 5

Eel Lee
Eel Lee

Reputation: 3543

I guess that underscore brings your attention.

As _ is a valid character to use in the method name, your

_("log-out")

is probably invocation of some _(String s) method, declared somewhere else.

Oh, and don't write methods named that way...

Upvotes: 4

Related Questions