TimSim
TimSim

Reputation: 4036

Java/Eclipse suggests method parameters

I created a class named Achievement with a constructor that accepts five parameters (id, title, description, datetime, notified). When I want to create a new achievement in another class, Eclipse suggests parameter names that have nothing to do with these parameters (matches them by type), but some other variables instead like:

 Achievement newAchievement = new Achievement(currentRank, APP_NAME, APP_NAME, savedDate, settings_achievementsound);

Is this something I can influence or does Eclipse make it automatic? It would be helpful if I could have descriptive parameter names, ideally the same names that are in the constructor.

Upvotes: 0

Views: 1606

Answers (2)

TWiStErRob
TWiStErRob

Reputation: 46480

There's a setting at Java > Editor > Content Assist > Fill method arguments and show guessed arguments > Insert best guessed arguments to make Eclipse match better variables to arguments, 60% of the time it works every time ;)

Try typing "new Achievement" and then select the constructor you want from the popup listbox via ENTER. After that you'll have those good or bad guessed arguments, go through them with TAB and select the variable that fits your purpose with UP/DOWN.

EDIT: Just realized you want descriptive names, then you need the other option: Insert parameter names!

Upvotes: 3

La-comadreja
La-comadreja

Reputation: 5755

One possibility is to create variables in your scope that represent the parameters you are passing into that constructor. Another possibility is to hardcode the arguments rather than declaring them as separate variables.

Upvotes: 0

Related Questions