Let's say we had a variable like this:
byte[] someByteArray;
And a method prototype like this:
public void someMethodRequiringString(String someByteArray);
And then we wanted to call our method on our byte array:
someMethodRequiringString(someByteArray);
Now we realize that our method requires a String instead. Let's also say we had already a conversion function in package Util called convertFromByteArrayToString(). What's the best way to get from
someMethodRequiringString(someByteArray);
to
someMethodRequiringString(Util.convertFromByteArrayToString(someByteArray));
My way is to put the cursor in front of someByteArray and type in Util., hit CTRL+Space and Eclipse suggests the method name of the conversion function. But, once I hit enter to choose this function, I will end up with something like this:
someMethodRequiringString(Util.convertFromByteArrayToString(bytearray)someByteArray);
where bytes is the input parameter name declared in Util.convertFromByteArrayToString(byte[] bytearray);. I know this might be a beginner's question but what's the best practice here?
You may want to have code completion overwrite the existing code (instead of inserting it before the existing text) as described here: http://www.vogella.com/articles/Eclipse/article.html#tips_completion
Alternatively you may also consider deleting the already written method argument someByteArray
hitting CtrlDelete 3 times (if your cursor is in front of it) or CtrlBackspace 3 times (if your cursor is directly after the argument). Then you add your Utils method via code completion as you do now and then you have the byte array argument be re-added by code completion (as Eclipse will suggest your variable as best choice, even without any character written yet).
The second alternative may sound complicated at first, but should make you type this much more quick if used often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With