Insert Dimensions to complete Expression/ReferenceType

后端 未结 7 1816
醉话见心
醉话见心 2021-01-03 21:55

I\'m a newbie to Java.

I have provided a short snippet from my code for BFS.

public int bfs(Person p, Person q) {
    private HashMap

        
7条回答
  •  星月不相逢
    2021-01-03 22:52

    It seems that this snippet is throwing around random keywords without any understanding - I would suggest a Java tutorial. First of all, generics are one of the main uses for boxing. boolean or any other primitives (you can recognise these by the fact that their identifiers are in lower-case and most IDEs will highlight them) cannot be used as a generic type, and their capitalised equivalent must be used (a simple wrapper class). Here, use HashMap.

    I'm not sure what is meant by marked = new marked... - clearly, marked is not a type and cannot be used in this context. new x(params) initialises an object of type x, passing its constructor params. new x(params) is the same but the generic type(s) of x are generics.

    Finally, new int is not at all valid - see my explanation above. Primitives are not objects, which means initialising them is meaningless and therefore invalid. Also, what do you expect this expression to yield? Something of type int, but you are not specifying which int. The correct syntax is a literal: count = x; where x is some integer within the range of int.

    As a side note, your method has an unclear name and variables may be initialised in the same line you declare them to simplify code.

提交回复
热议问题