Java - What do constructor type arguments mean when placed *before* the type?How to round a number to n decimal places in JavaWhat is the difference between public, protected, package-private and private in Java?How do I call one constructor from another in Java?When to use LinkedList over ArrayList in Java?What does 'synchronized' mean?What is the Java equivalent for LINQ?What is a daemon thread in Java?Java: when to use static methodsWhat are the -Xms and -Xmx parameters when starting JVM?What does “Could not find or load main class” mean?

MAXDOP Settings for SQL Server 2014

Is it possible to have a strip of cold climate in the middle of a planet?

Open a doc from terminal, but not by its name

On a tidally locked planet, would time be quantized?

Proving a function is onto where f(x)=|x|.

What's the difference between 違法 and 不法?

How to align and center standalone amsmath equations?

How should I respond when I lied about my education and the company finds out through background check?

When quoting, must I also copy hyphens used to divide words that continue on the next line?

Varistor? Purpose and principle

Did arcade monitors have same pixel aspect ratio as TV sets?

Find last 3 digits of this monster number

Visiting the UK as unmarried couple

We have a love-hate relationship

Can the Supreme Court overturn an impeachment?

Should I install hardwood flooring or cabinets first?

Difference between -| and |- in TikZ

What linear sensor for a keyboard?

Can a significant change in incentives void an employment contract?

Why has "pence" been used in this sentence, not "pences"?

Is there a word to describe the feeling of being transfixed out of horror?

Create all possible words using a set or letters

My friend sent me a screenshot of a transaction hash, but when I search for it I find divergent data. What happened?

Why did the HMS Bounty go back to a time when whales are already rare?



Java - What do constructor type arguments mean when placed *before* the type?


How to round a number to n decimal places in JavaWhat is the difference between public, protected, package-private and private in Java?How do I call one constructor from another in Java?When to use LinkedList over ArrayList in Java?What does 'synchronized' mean?What is the Java equivalent for LINQ?What is a daemon thread in Java?Java: when to use static methodsWhat are the -Xms and -Xmx parameters when starting JVM?What does “Could not find or load main class” mean?













7















I've recently come across this unusual (to me) Java syntax...here's an example of it:



List list = new <String, Long>ArrayList();


Notice the positioning of the <String, Long> type arguments...it's not after the type as normal but before. I don't mind admitting I've never seen this syntax before. Also note there are 2 type arguments when ArrayList only has 1.



Does the positioning of the type arguments have the same meaning as putting them after the type? If not, what does the different positioning mean?



Why is it legal to have 2 type arguments when ArrayList only has 1?



I've searched the usual places, eg. Angelika Langer and on here but can't find any mention of this syntax anywhere apart from the grammar rules in the Java grammar file on the ANTLR project.










share|improve this question






















  • Yeah so do I, I'm not asking how to create a list lol

    – Nathan Adams
    1 hour ago






  • 2





    A constructor may have type arguments that are placed there (this particular constructor hasn’t, so <String, Long> is just ignored). See Generics Constructor.

    – Ole V.V.
    1 hour ago







  • 1





    OK that makes sense, although it's weird that there's no compile error even though there's no type arguments on the constructor

    – Nathan Adams
    1 hour ago






  • 1





    No error, but you get a warning about raw types. Don't use raw types. Do use the diamond operator. List<String> list = new ArrayList<>();

    – Elliott Frisch
    1 hour ago











  • @OleV.V. if you wanna put your comment and link as an answer I'll accept it

    – Nathan Adams
    1 hour ago















7















I've recently come across this unusual (to me) Java syntax...here's an example of it:



List list = new <String, Long>ArrayList();


Notice the positioning of the <String, Long> type arguments...it's not after the type as normal but before. I don't mind admitting I've never seen this syntax before. Also note there are 2 type arguments when ArrayList only has 1.



Does the positioning of the type arguments have the same meaning as putting them after the type? If not, what does the different positioning mean?



Why is it legal to have 2 type arguments when ArrayList only has 1?



I've searched the usual places, eg. Angelika Langer and on here but can't find any mention of this syntax anywhere apart from the grammar rules in the Java grammar file on the ANTLR project.










share|improve this question






















  • Yeah so do I, I'm not asking how to create a list lol

    – Nathan Adams
    1 hour ago






  • 2





    A constructor may have type arguments that are placed there (this particular constructor hasn’t, so <String, Long> is just ignored). See Generics Constructor.

    – Ole V.V.
    1 hour ago







  • 1





    OK that makes sense, although it's weird that there's no compile error even though there's no type arguments on the constructor

    – Nathan Adams
    1 hour ago






  • 1





    No error, but you get a warning about raw types. Don't use raw types. Do use the diamond operator. List<String> list = new ArrayList<>();

    – Elliott Frisch
    1 hour ago











  • @OleV.V. if you wanna put your comment and link as an answer I'll accept it

    – Nathan Adams
    1 hour ago













7












7








7


1






I've recently come across this unusual (to me) Java syntax...here's an example of it:



List list = new <String, Long>ArrayList();


Notice the positioning of the <String, Long> type arguments...it's not after the type as normal but before. I don't mind admitting I've never seen this syntax before. Also note there are 2 type arguments when ArrayList only has 1.



Does the positioning of the type arguments have the same meaning as putting them after the type? If not, what does the different positioning mean?



Why is it legal to have 2 type arguments when ArrayList only has 1?



I've searched the usual places, eg. Angelika Langer and on here but can't find any mention of this syntax anywhere apart from the grammar rules in the Java grammar file on the ANTLR project.










share|improve this question














I've recently come across this unusual (to me) Java syntax...here's an example of it:



List list = new <String, Long>ArrayList();


Notice the positioning of the <String, Long> type arguments...it's not after the type as normal but before. I don't mind admitting I've never seen this syntax before. Also note there are 2 type arguments when ArrayList only has 1.



Does the positioning of the type arguments have the same meaning as putting them after the type? If not, what does the different positioning mean?



Why is it legal to have 2 type arguments when ArrayList only has 1?



I've searched the usual places, eg. Angelika Langer and on here but can't find any mention of this syntax anywhere apart from the grammar rules in the Java grammar file on the ANTLR project.







java grammar






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Nathan AdamsNathan Adams

1638




1638












  • Yeah so do I, I'm not asking how to create a list lol

    – Nathan Adams
    1 hour ago






  • 2





    A constructor may have type arguments that are placed there (this particular constructor hasn’t, so <String, Long> is just ignored). See Generics Constructor.

    – Ole V.V.
    1 hour ago







  • 1





    OK that makes sense, although it's weird that there's no compile error even though there's no type arguments on the constructor

    – Nathan Adams
    1 hour ago






  • 1





    No error, but you get a warning about raw types. Don't use raw types. Do use the diamond operator. List<String> list = new ArrayList<>();

    – Elliott Frisch
    1 hour ago











  • @OleV.V. if you wanna put your comment and link as an answer I'll accept it

    – Nathan Adams
    1 hour ago

















  • Yeah so do I, I'm not asking how to create a list lol

    – Nathan Adams
    1 hour ago






  • 2





    A constructor may have type arguments that are placed there (this particular constructor hasn’t, so <String, Long> is just ignored). See Generics Constructor.

    – Ole V.V.
    1 hour ago







  • 1





    OK that makes sense, although it's weird that there's no compile error even though there's no type arguments on the constructor

    – Nathan Adams
    1 hour ago






  • 1





    No error, but you get a warning about raw types. Don't use raw types. Do use the diamond operator. List<String> list = new ArrayList<>();

    – Elliott Frisch
    1 hour ago











  • @OleV.V. if you wanna put your comment and link as an answer I'll accept it

    – Nathan Adams
    1 hour ago
















Yeah so do I, I'm not asking how to create a list lol

– Nathan Adams
1 hour ago





Yeah so do I, I'm not asking how to create a list lol

– Nathan Adams
1 hour ago




2




2





A constructor may have type arguments that are placed there (this particular constructor hasn’t, so <String, Long> is just ignored). See Generics Constructor.

– Ole V.V.
1 hour ago






A constructor may have type arguments that are placed there (this particular constructor hasn’t, so <String, Long> is just ignored). See Generics Constructor.

– Ole V.V.
1 hour ago





1




1





OK that makes sense, although it's weird that there's no compile error even though there's no type arguments on the constructor

– Nathan Adams
1 hour ago





OK that makes sense, although it's weird that there's no compile error even though there's no type arguments on the constructor

– Nathan Adams
1 hour ago




1




1





No error, but you get a warning about raw types. Don't use raw types. Do use the diamond operator. List<String> list = new ArrayList<>();

– Elliott Frisch
1 hour ago





No error, but you get a warning about raw types. Don't use raw types. Do use the diamond operator. List<String> list = new ArrayList<>();

– Elliott Frisch
1 hour ago













@OleV.V. if you wanna put your comment and link as an answer I'll accept it

– Nathan Adams
1 hour ago





@OleV.V. if you wanna put your comment and link as an answer I'll accept it

– Nathan Adams
1 hour ago












2 Answers
2






active

oldest

votes


















5














This is unusual alright, but fully valid Java. A class may have a generic constructor, for example:



public class TypeWithGenericConstructor 

public <T> TypeWithGenericConstructor(T arg)
// TODO Auto-generated constructor stub





I suppose that more often than not we don’t need to make the type argument explicit. For example:



 new TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


Now T is clearly LocalDate. However there may be cases where Java cannot infer (deduce) the type argument. Then we supply it explicitly using the syntax from your question:



 new <LocalDate>TypeWithGenericConstructor(null);


Of course we may also supply it even though it is not necessary if we think it helps readability or for whatever reason:



 new <LocalDate>TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


In your question you seem to be calling the java.util.ArrayList constructor. That constructor is not generic (only the ArrayList class as a whole is, that’s something else). Why Java allows you to supply type arguments in the call when they are not used, I don’t know, but it does. My Eclipse gives me a warning:




Unused type arguments for the non generic constructor ArrayList() of
type ArrayList; it should not be parameterized with arguments




But it’s not an error, and the program runs fine (I additionally get warnings about missing type arguments for List and ArrayList, but that again is a different story).




Does the positioning of the type arguments have the same meaning as
putting them after the type? If not, what does the different
positioning mean?




No, it’s different. The usual type argument/s after the type (ArrayList<Integer>) are for the generic class. The type arguments before are for the * constructor*.



The two forms may also be combined:



 List<Integer> list = new <String, Long>ArrayList<Integer>();


I would consider this a bit more correct since we can now see that the list stores Integer objects (I’d still prefer to leave out the meaningless <String, Long>, of course).




Why is it legal to have 2 type arguments when ArrayList only has 1?




First, if you supply type arguments before the type, you should supply the correct number for the constructor, not for the class, so it hasn’t got anything to do with how many type arguments the ArrayList class has got. That really means that in this case you shouldn’t supply any since the constructor doesn’t take type arguments (it’s not generic). When you supply some anyway, they are ignored, which is why it doesn’t matter how many or how few you supply (I repeat, I don’t know why Java allows you to supply them meaninglessly).






share|improve this answer

























  • But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

    – jaspreet
    46 mins ago











  • Thanks for asking, @jaspreet. Please see my edit.

    – Ole V.V.
    35 mins ago


















0














Here:



List list = new <String, Long>ArrayList();


You have a raw type, as you don't specify a generic type for your list object on the left hand side. Providing the generic type on the right hand side is mostly not required in the first place, as the compiler can defer the generic type.



A bit of guessing here: due to fact that list itself is a raw type, the type specification given to new is somehow ignored. The other answer nicely explains why you can have type parameters in that place. But because a raw type doesn't care about type parameters, the compiler doesn't bother checking that detail here.





share






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330697%2fjava-what-do-constructor-type-arguments-mean-when-placed-before-the-type%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    This is unusual alright, but fully valid Java. A class may have a generic constructor, for example:



    public class TypeWithGenericConstructor 

    public <T> TypeWithGenericConstructor(T arg)
    // TODO Auto-generated constructor stub





    I suppose that more often than not we don’t need to make the type argument explicit. For example:



     new TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    Now T is clearly LocalDate. However there may be cases where Java cannot infer (deduce) the type argument. Then we supply it explicitly using the syntax from your question:



     new <LocalDate>TypeWithGenericConstructor(null);


    Of course we may also supply it even though it is not necessary if we think it helps readability or for whatever reason:



     new <LocalDate>TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    In your question you seem to be calling the java.util.ArrayList constructor. That constructor is not generic (only the ArrayList class as a whole is, that’s something else). Why Java allows you to supply type arguments in the call when they are not used, I don’t know, but it does. My Eclipse gives me a warning:




    Unused type arguments for the non generic constructor ArrayList() of
    type ArrayList; it should not be parameterized with arguments




    But it’s not an error, and the program runs fine (I additionally get warnings about missing type arguments for List and ArrayList, but that again is a different story).




    Does the positioning of the type arguments have the same meaning as
    putting them after the type? If not, what does the different
    positioning mean?




    No, it’s different. The usual type argument/s after the type (ArrayList<Integer>) are for the generic class. The type arguments before are for the * constructor*.



    The two forms may also be combined:



     List<Integer> list = new <String, Long>ArrayList<Integer>();


    I would consider this a bit more correct since we can now see that the list stores Integer objects (I’d still prefer to leave out the meaningless <String, Long>, of course).




    Why is it legal to have 2 type arguments when ArrayList only has 1?




    First, if you supply type arguments before the type, you should supply the correct number for the constructor, not for the class, so it hasn’t got anything to do with how many type arguments the ArrayList class has got. That really means that in this case you shouldn’t supply any since the constructor doesn’t take type arguments (it’s not generic). When you supply some anyway, they are ignored, which is why it doesn’t matter how many or how few you supply (I repeat, I don’t know why Java allows you to supply them meaninglessly).






    share|improve this answer

























    • But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

      – jaspreet
      46 mins ago











    • Thanks for asking, @jaspreet. Please see my edit.

      – Ole V.V.
      35 mins ago















    5














    This is unusual alright, but fully valid Java. A class may have a generic constructor, for example:



    public class TypeWithGenericConstructor 

    public <T> TypeWithGenericConstructor(T arg)
    // TODO Auto-generated constructor stub





    I suppose that more often than not we don’t need to make the type argument explicit. For example:



     new TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    Now T is clearly LocalDate. However there may be cases where Java cannot infer (deduce) the type argument. Then we supply it explicitly using the syntax from your question:



     new <LocalDate>TypeWithGenericConstructor(null);


    Of course we may also supply it even though it is not necessary if we think it helps readability or for whatever reason:



     new <LocalDate>TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    In your question you seem to be calling the java.util.ArrayList constructor. That constructor is not generic (only the ArrayList class as a whole is, that’s something else). Why Java allows you to supply type arguments in the call when they are not used, I don’t know, but it does. My Eclipse gives me a warning:




    Unused type arguments for the non generic constructor ArrayList() of
    type ArrayList; it should not be parameterized with arguments




    But it’s not an error, and the program runs fine (I additionally get warnings about missing type arguments for List and ArrayList, but that again is a different story).




    Does the positioning of the type arguments have the same meaning as
    putting them after the type? If not, what does the different
    positioning mean?




    No, it’s different. The usual type argument/s after the type (ArrayList<Integer>) are for the generic class. The type arguments before are for the * constructor*.



    The two forms may also be combined:



     List<Integer> list = new <String, Long>ArrayList<Integer>();


    I would consider this a bit more correct since we can now see that the list stores Integer objects (I’d still prefer to leave out the meaningless <String, Long>, of course).




    Why is it legal to have 2 type arguments when ArrayList only has 1?




    First, if you supply type arguments before the type, you should supply the correct number for the constructor, not for the class, so it hasn’t got anything to do with how many type arguments the ArrayList class has got. That really means that in this case you shouldn’t supply any since the constructor doesn’t take type arguments (it’s not generic). When you supply some anyway, they are ignored, which is why it doesn’t matter how many or how few you supply (I repeat, I don’t know why Java allows you to supply them meaninglessly).






    share|improve this answer

























    • But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

      – jaspreet
      46 mins ago











    • Thanks for asking, @jaspreet. Please see my edit.

      – Ole V.V.
      35 mins ago













    5












    5








    5







    This is unusual alright, but fully valid Java. A class may have a generic constructor, for example:



    public class TypeWithGenericConstructor 

    public <T> TypeWithGenericConstructor(T arg)
    // TODO Auto-generated constructor stub





    I suppose that more often than not we don’t need to make the type argument explicit. For example:



     new TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    Now T is clearly LocalDate. However there may be cases where Java cannot infer (deduce) the type argument. Then we supply it explicitly using the syntax from your question:



     new <LocalDate>TypeWithGenericConstructor(null);


    Of course we may also supply it even though it is not necessary if we think it helps readability or for whatever reason:



     new <LocalDate>TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    In your question you seem to be calling the java.util.ArrayList constructor. That constructor is not generic (only the ArrayList class as a whole is, that’s something else). Why Java allows you to supply type arguments in the call when they are not used, I don’t know, but it does. My Eclipse gives me a warning:




    Unused type arguments for the non generic constructor ArrayList() of
    type ArrayList; it should not be parameterized with arguments




    But it’s not an error, and the program runs fine (I additionally get warnings about missing type arguments for List and ArrayList, but that again is a different story).




    Does the positioning of the type arguments have the same meaning as
    putting them after the type? If not, what does the different
    positioning mean?




    No, it’s different. The usual type argument/s after the type (ArrayList<Integer>) are for the generic class. The type arguments before are for the * constructor*.



    The two forms may also be combined:



     List<Integer> list = new <String, Long>ArrayList<Integer>();


    I would consider this a bit more correct since we can now see that the list stores Integer objects (I’d still prefer to leave out the meaningless <String, Long>, of course).




    Why is it legal to have 2 type arguments when ArrayList only has 1?




    First, if you supply type arguments before the type, you should supply the correct number for the constructor, not for the class, so it hasn’t got anything to do with how many type arguments the ArrayList class has got. That really means that in this case you shouldn’t supply any since the constructor doesn’t take type arguments (it’s not generic). When you supply some anyway, they are ignored, which is why it doesn’t matter how many or how few you supply (I repeat, I don’t know why Java allows you to supply them meaninglessly).






    share|improve this answer















    This is unusual alright, but fully valid Java. A class may have a generic constructor, for example:



    public class TypeWithGenericConstructor 

    public <T> TypeWithGenericConstructor(T arg)
    // TODO Auto-generated constructor stub





    I suppose that more often than not we don’t need to make the type argument explicit. For example:



     new TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    Now T is clearly LocalDate. However there may be cases where Java cannot infer (deduce) the type argument. Then we supply it explicitly using the syntax from your question:



     new <LocalDate>TypeWithGenericConstructor(null);


    Of course we may also supply it even though it is not necessary if we think it helps readability or for whatever reason:



     new <LocalDate>TypeWithGenericConstructor(LocalDate.now(ZoneId.systemDefault()));


    In your question you seem to be calling the java.util.ArrayList constructor. That constructor is not generic (only the ArrayList class as a whole is, that’s something else). Why Java allows you to supply type arguments in the call when they are not used, I don’t know, but it does. My Eclipse gives me a warning:




    Unused type arguments for the non generic constructor ArrayList() of
    type ArrayList; it should not be parameterized with arguments




    But it’s not an error, and the program runs fine (I additionally get warnings about missing type arguments for List and ArrayList, but that again is a different story).




    Does the positioning of the type arguments have the same meaning as
    putting them after the type? If not, what does the different
    positioning mean?




    No, it’s different. The usual type argument/s after the type (ArrayList<Integer>) are for the generic class. The type arguments before are for the * constructor*.



    The two forms may also be combined:



     List<Integer> list = new <String, Long>ArrayList<Integer>();


    I would consider this a bit more correct since we can now see that the list stores Integer objects (I’d still prefer to leave out the meaningless <String, Long>, of course).




    Why is it legal to have 2 type arguments when ArrayList only has 1?




    First, if you supply type arguments before the type, you should supply the correct number for the constructor, not for the class, so it hasn’t got anything to do with how many type arguments the ArrayList class has got. That really means that in this case you shouldn’t supply any since the constructor doesn’t take type arguments (it’s not generic). When you supply some anyway, they are ignored, which is why it doesn’t matter how many or how few you supply (I repeat, I don’t know why Java allows you to supply them meaninglessly).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 37 mins ago

























    answered 1 hour ago









    Ole V.V.Ole V.V.

    31.2k63956




    31.2k63956












    • But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

      – jaspreet
      46 mins ago











    • Thanks for asking, @jaspreet. Please see my edit.

      – Ole V.V.
      35 mins ago

















    • But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

      – jaspreet
      46 mins ago











    • Thanks for asking, @jaspreet. Please see my edit.

      – Ole V.V.
      35 mins ago
















    But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

    – jaspreet
    46 mins ago





    But how it is allowing 2 arguments <String, Long>.The list will allow storing which type of data?

    – jaspreet
    46 mins ago













    Thanks for asking, @jaspreet. Please see my edit.

    – Ole V.V.
    35 mins ago





    Thanks for asking, @jaspreet. Please see my edit.

    – Ole V.V.
    35 mins ago













    0














    Here:



    List list = new <String, Long>ArrayList();


    You have a raw type, as you don't specify a generic type for your list object on the left hand side. Providing the generic type on the right hand side is mostly not required in the first place, as the compiler can defer the generic type.



    A bit of guessing here: due to fact that list itself is a raw type, the type specification given to new is somehow ignored. The other answer nicely explains why you can have type parameters in that place. But because a raw type doesn't care about type parameters, the compiler doesn't bother checking that detail here.





    share



























      0














      Here:



      List list = new <String, Long>ArrayList();


      You have a raw type, as you don't specify a generic type for your list object on the left hand side. Providing the generic type on the right hand side is mostly not required in the first place, as the compiler can defer the generic type.



      A bit of guessing here: due to fact that list itself is a raw type, the type specification given to new is somehow ignored. The other answer nicely explains why you can have type parameters in that place. But because a raw type doesn't care about type parameters, the compiler doesn't bother checking that detail here.





      share

























        0












        0








        0







        Here:



        List list = new <String, Long>ArrayList();


        You have a raw type, as you don't specify a generic type for your list object on the left hand side. Providing the generic type on the right hand side is mostly not required in the first place, as the compiler can defer the generic type.



        A bit of guessing here: due to fact that list itself is a raw type, the type specification given to new is somehow ignored. The other answer nicely explains why you can have type parameters in that place. But because a raw type doesn't care about type parameters, the compiler doesn't bother checking that detail here.





        share













        Here:



        List list = new <String, Long>ArrayList();


        You have a raw type, as you don't specify a generic type for your list object on the left hand side. Providing the generic type on the right hand side is mostly not required in the first place, as the compiler can defer the generic type.



        A bit of guessing here: due to fact that list itself is a raw type, the type specification given to new is somehow ignored. The other answer nicely explains why you can have type parameters in that place. But because a raw type doesn't care about type parameters, the compiler doesn't bother checking that detail here.






        share











        share


        share










        answered 2 mins ago









        GhostCatGhostCat

        95.1k1793156




        95.1k1793156



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55330697%2fjava-what-do-constructor-type-arguments-mean-when-placed-before-the-type%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

            Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

            How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2