Java – eclipse shortcut for declaring variable names as method parameters
Suppose we have such a variable:
byte[] someByteArray;
And such a method prototype:
public void someMethodRequiringString(String someByteArray);
Then we want to call our method on the byte array:
someMethodRequiringString(someByteArray);
Now we realize that our method needs a string We also said that we have used a conversion function called convertfrombytearraytostring() in the package util What is the best way
someMethodRequiringString(someByteArray);
to
someMethodRequiringString(Util.convertFromByteArrayToString(someByteArray));
My method is to place the cursor in front of somebytearray and enter util, Click Ctrl space, and eclipse suggests the method name of the conversion function However, once I press enter to select this function, I will eventually get this result:
someMethodRequiringString(Util.convertFromByteArrayToString(bytearray)someByteArray);
Where bytes is in util convertFromByteArrayToString(byte [] bytearray); The name of the input parameter declared in I know this may be a beginner's problem, but what's the best practice here?
Solution
You may want code completion to overwrite existing code (rather than insert before existing text), as follows: http://www.vogella.com/articles/Eclipse/article.html#tips_completion
Alternatively, you can also consider deleting the written method parameter somebytearray, press ctrldelete 3 times (if the cursor is in front of it) or ctrlbackspace 3 times (if the cursor is directly behind the parameter) Then, as now, add the utils method through code, and then re add the byte array parameters through code (because eclipse will recommend your variables as the best choice, even if you don't write any characters)
The second option may sound complicated, but if used frequently, it should allow you to enter more quickly