2017-01-20 16 views
0

このコードでは、2つの混乱しているケースが表示されます。コンストラクター名の前にジェネリックを置き、その後に異なる結果が表示されます。一般的なコンストラクタはエラーを呼び出すか?

class moke<T> { 
    T ob; 
    moke(T ob){ 
     this.ob=ob; 
    } 
    T ret(){ 
     return ob; 
     } 
    } 
    class ramirez{ 
     public static void main(String args[]){ 
     moke<Integer> one= new moke<Integer>(9);// it's ok 
     moke<String> two=new moke<Integer>("ASDASD"); // error appears here which is ok 
     moke<String> three= new <Integer>moke("knmkm"); //no error here WHY?? 
     moke<String> four=new <String>moke(9); //No error hereWHY?? 


    }} 

ので、最初の質問に<Type>constructor()constructor<Type>()

+1

(http://stackoverflow.com/questions/12231453/syntax-for-creating-a-two-dimensional-array)[2次元配列を作成するための構文]の可能性のある重複したポストあたり – luk2302

+1

一つ質問してください(例:重複して1つを閉じて2番目のものに答えるか、別々に閉じてしまう理由) – luk2302

+0

[ジェネリックでないメソッドやコンストラクタに明示的な型引数を与えるのはなぜですか?](http://stackoverflow.com/questions/22174022 /なぜなら与えない明示的な型引数を非genericメソッドまたはコンストラクタにするc) – Calculator

答えて

0

回答の違いです:これをより明確にするために

// here {1,2,3} is an array initializer you may use to define the array 
int[] arr = {1,2,3}; 

// this does not work, because this is an assignment expression and not a definition of the array 
arr = {1,2,3}; 

は、ちょうどarrを想像することは(おそらく異なる)サイズの配列です実行時に決定される。この割り当てはどのように機能しますか?

2番目の質問についてはまだ回答がありません。奇妙に見える。しかし、stackoverflowの各質問の新しい投稿を作成してください。

関連する問題