简体   繁体   English

Eclipse快捷方式将变量名称声明为方法参数

[英]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.

相关问题 Eclipse - 基于return或get声明变量(快捷方式) - Eclipse - Declare variable based on return or get (Shortcut) Eclipse键盘快捷键,用于将参数传递给方法 - Eclipse keyboard shortcut for passing a parameter to a method Eclipse快捷方式查找函数名称 - Eclipse shortcut to find function name Eclipse格式化方法调用的快捷方式 - Eclipse shortcut to format a method call 方法名称 execute 该语句不声明 OUT 参数。 使用 { ?= call ... } 声明一个 - method Name execute This statement does not declare an OUT parameter. Use { ?= call ... } to declare one 设置实例变量与方法参数同名吗? - Setting instance variable with same name as method parameter? Intellij的方法参数完成快捷方式? - Method Parameter Completion Shortcut for Intellij? Eclipse快捷方式来接受带有附加的同名小写起始变量的类型建议 - Eclipse shortcut to accept type proposal with appended same-name lowercase starting variable 在 IntelliJ 中,是否有一种快捷方式可以获取我已经输入的变量作为我想要输入的方法中的参数? - In IntelliJ, is there a shortcut to get variable I've already typed to be a parameter in a method I want to type? Eclipse快捷方式自动填充有用类型的实例变量? - Eclipse shortcut to autofill a usefull type of instance variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM