[問題] 某公司面試題目求解

看板java作者 (陽光老哥 fighting!!!)時間3年前 (2020/07/03 08:58), 編輯推噓2(2018)
留言20則, 5人參與, 3年前最新討論串1/1
public class Breakkker { public static void main(String[] args) { GenericParser parser = new GenericParser(); Long longValue = parser.parse(Long.class, "123"); System.out.println(longValue); Integer intValue = parser.parse(Integer.class, "123"); System.out.println(intValue); Float floatValue = parser.parse(Float.class, "123.45"); System.out.println(floatValue); } } Output : 123 123 123.45 要你寫出 class GenericParser{ } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.15.191.56 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/java/M.1593737887.A.7AC.html

07/03 10:46, 3年前 , 1F

07/03 17:15, 3年前 , 2F
這一個雖然不像是面試時能寫得出來的答案但還是貼一下
07/03 17:15, 2F

07/03 17:15, 3年前 , 3F

07/04 00:30, 3年前 , 4F
真的強 看到之後 感覺好像很簡單 其實真的不知道怎下手
07/04 00:30, 4F

07/04 00:39, 3年前 , 5F
LPH大大 輸入後有錯誤 GenericParser parser = new Gene
07/04 00:39, 5F

07/04 00:44, 3年前 , 6F
public static class Generic.. 可以 但不加static 要怎改
07/04 00:44, 6F

07/04 01:27, 3年前 , 7F
不加 static 就是你要分成另一個 java 檔
07/04 01:27, 7F

07/04 01:27, 3年前 , 8F
話說會寫 java 應該知道一個 class 一個原始檔的規則吧?
07/04 01:27, 8F

07/04 03:49, 3年前 , 9F
恩恩 知道 但沒仔細研究過 我新手 謝謝指導
07/04 03:49, 9F

07/04 13:02, 3年前 , 10F
static跟分不分檔案無關吧,是放錯地方吧
07/04 13:02, 10F

07/04 13:05, 3年前 , 11F
一個java檔案只能有一個public class,沒public的可以多個
07/04 13:05, 11F

07/04 13:05, 3年前 , 12F
但是必須是top level class
07/04 13:05, 12F

07/04 13:05, 3年前 , 13F
inner class才有分是否static,static的就跟top level clas
07/04 13:05, 13F

07/04 13:07, 3年前 , 14F
s很像,只是可以存取enclosing class的private member
07/04 13:07, 14F

07/04 13:07, 3年前 , 15F
非static的inner class,一定綁定一個enclosing class的
07/04 13:07, 15F

07/04 13:10, 3年前 , 16F
instance,要在enclosing class的非static context中才能直
07/04 13:10, 16F

07/04 13:10, 3年前 , 17F
接new,或是用outerInstance.new InnerClass()
07/04 13:10, 17F

07/04 13:27, 3年前 , 18F

07/04 13:27, 3年前 , 19F
雖然可以不過建議還是一個檔案一個top level class
07/04 13:27, 19F

07/04 23:51, 3年前 , 20F
推樓上
07/04 23:51, 20F
文章代碼(AID): #1U_eAVUi (java)
文章代碼(AID): #1U_eAVUi (java)