[英]Eclipse shortcut to declare a variable name as method parameter
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. 现在我们意识到我们的方法需要一个String。 Let's also say we had already a conversion function in package Util called convertFromByteArrayToString() .
我们还说我们已经在包Util中使用了一个名为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. 我的方法是将光标放在someByteArray前面并输入Util。 , hit CTRL+Space and Eclipse suggests the method name of the conversion function.
,点击CTRL + Space,Eclipse建议转换函数的方法名称。 But, once I hit enter to choose this function, I will end up with something like this:
但是,一旦我按Enter键选择此功能,我最终会得到这样的结果:
someMethodRequiringString(Util.convertFromByteArrayToString(bytearray)someByteArray);
where bytes is the input parameter name declared in Util.convertFromByteArrayToString(byte[] bytearray); 其中bytes是在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 您可能希望代码完成覆盖现有代码(而不是在现有文本之前插入),如下所述: http : //www.vogella.com/articles/Eclipse/article.html#tips_completion
Alternatively you may also consider deleting the already written method argument someByteArray
hitting Ctrl Delete 3 times (if your cursor is in front of it) or Ctrl Backspace 3 times (if your cursor is directly after the argument). 或者,您也可以考虑删除已写入的方法参数
someByteArray
按Ctrl Delete 3次(如果光标位于其前面)或Ctrl Backspace 3次(如果光标直接位于参数之后)。 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). 然后像现在一样通过代码完成添加Utils方法,然后通过代码完成重新添加字节数组参数(因为Eclipse将建议您的变量作为最佳选择,即使没有编写任何字符)。
The second alternative may sound complicated at first, but should make you type this much more quick if used often. 第二种选择可能听起来很复杂,但如果经常使用,应该让你更快速地输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.