當我使用該方法時,是否有任何可能的方法來推薦參數? (就像註釋?)如何在java中推薦參數?
我做了很多靜態最終的字符串參數爲url連接,我想知道我是否使用正確的輸入參數或者當我代碼。
下面是我的例子。
public void myRequest(String inputParameter) {
String requestURL = "";
static final String ex1 = "http://example.com/xml1";
static final String ex2 = "http://example.com/xml2";
static final String ex3 = "http://example.com/xml3";
static final String ex4 = "http://example.com/xml4";
static final String ex5 = "http://example.com/xml5";
static final String ex6 = "http://example.com/xml6";
static final String ex7 = "http://example.com/xml7";
// too many..
// ....
static final String ex125 = "http://example.com/xm125";
if(inputParameter.equals("ex1")) {
requestURL = ex1;
} else if(inputParameter.equals("ex2")) {
requestURL = ex2;
}
// just like this..
// .....
else if(inputParameter.equals("ex125")) {
requestURL = ex125;
}
String requestURL = inputParameter;
URL url = new URL(requestURL);
URLConnection urlConnection = url.openConnection();
// below codes are unnecessary.
}
,我會用這種方法,在「主」的方法
public static void main(String[] args) {
myRequest("ex1"); // this!!
}
的一點是,當我寫的方法「myRequest()」,IDE會告訴我有關參數的信息(當光標位於'('和')'之間時)。唯一可以注意到的是「你應該寫String對象」。不是「你可以使用ex1這意味着加載ex1.xml,ex2意味着ex2.xml或... ex125意思是xm125.xml」
如果我的希望成真,結果就像是這樣。
(寫作方法)
myRequest(|); // there is cursor between (and)
「我應該要求什麼XML?嗯..還有EX1到ex125。行.. EX1意味着..我的家鄉歷史.. EX2意味着我校的歷史。 。和嗯..我應該用ex4 ok!「 (我下面寫的方法)
myRequest("ex4");
我想IDE通知我字符串參數我應該使用什麼。
有什麼可能的辦法嗎?
@ScaryWombat但是,怎麼樣?我認爲IDE不知道該靜態最終的字符串變量是否與輸入參數有關係... – TyeolRik
@GhostCat對不起,我工作遲到。你能查看我的新增範例嗎? – TyeolRik
@GhostCat 嗯,我不知道,因爲我在這裏是新手。我所做的是點擊你的答案旁邊的複選框LOL – TyeolRik