代码之家  ›  专栏  ›  技术社区  ›  Arezoo Bagherzadi

在Java中使用< >和不使用它有什么区别?[副本]

  •  1
  • Arezoo Bagherzadi  · 技术社区  · 6 年前

    这个问题已经有了答案:

    我有一段这样的代码:

    @RequestMapping(value = "/find/{id}")
    @GetMapping
    public ResponseEntity<QuestionModel> find(@PathVariable("id") Long id) {
        Question question = questionService.find(id);
        QuestionModel questionModel = new QuestionModel(question);
        **return new ResponseEntity<>(questionModel, HttpStatus.OK);**
    }
    

    我想知道这两者之间有什么区别:

    @RequestMapping(value = "/find/{id}")
    @GetMapping
    public ResponseEntity<QuestionModel> find(@PathVariable("id") Long id) {
        Question question = questionService.find(id);
        QuestionModel questionModel = new QuestionModel(question);
        **return new ResponseEntity(questionModel, HttpStatus.OK);**
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Zabuzard Louis-Philippe Lebouthillier    6 年前

    <...> < What is a raw type and why shouldn't we use it?

    <> <Foo> var What is the point of the diamond operator in Java 7?

    // Are the same
    List<Integer> values = new ArrayList<Integer>();
    List<Integer> values = new ArrayList<>();
    
    // Raw types, don't use if > Java 5
    List values = new ArrayList();
    // Assigning a raw-type to a generic variable, mixing both, don't use
    List<Integer> values = new ArrayList();