title: How to return a singleton list in an API?
body: <p>I am in the middle of learning to create a Java API using Eclipse IDE and Spring-Boot framework. Therefore, I am facing a syntax issue which I am not able to resolve. Below is my code for your reference:</p>
  <pre><code>package first.microservice.moviecatalogservice.resources;
  
  import java.util.Collections;
  import java.util.List;
  
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RestController;
  import first.microservice.moviecatalogservice.models.CatalogItem;
  
  @RestController 
  @RequestMapping(&quot;/catalog&quot;)
  public class MovieCatalogResource {
          
      @RequestMapping(&quot;/{user_id}&quot;)   
      public List&lt;CatalogItem&gt; getCatalog(@PathVariable(&quot;user_id&quot;) String user_id)
          {
              return Collections.singletonList(
                       &lt;CatalogItem&gt; new CatalogItem(name: &quot;DonJon&quot;, desc: &quot;Test&quot;, rating: 4)
                      );
          }
  }
  </code></pre>
  <p>Another code which has the CatalogItem class:</p>
  <pre><code>package first.microservice.moviecatalogservice.models;
  
  public class CatalogItem {
  
      private String Name;
      private String Desc;
      private int Rating;
      
      public CatalogItem(String name, String desc, int rating) {
          Name = name;
          Desc = desc;
          Rating = rating;
      }
      
      public String getName() {
          return Name;
      }
      public void setName(String name) {
          Name = name;
      }
      public String getDesc() {
          return Desc;
      }
      public void setDesc(String desc) {
          Desc = desc;
      }
      public int getRating() {
          return Rating;
      }
      public void setRating(int rating) {
          Rating = rating;
      }
      
      
  }
  </code></pre>
  <p>I wish to enter the URL pattern to display the hardcoded values of the catalogitem to display on the browser.</p>
  <p>I am facing error in the following line:</p>
  <pre><code>return Collections.singletonList(
                       &lt;CatalogItem&gt; new CatalogItem(name: &quot;DonJon&quot;, desc: &quot;Test&quot;, rating: 4)
                      );
  </code></pre>
  <p>The error states that:</p>
  <pre><code>The method singletonList(T) in the type Collections is not applicable for the arguments (CatalogItem)
  
  Multiple markers at this line
      - Syntax error on token &quot;&lt;&quot;, invalid Expression
      - Syntax error on token &quot;:&quot;, invalid     AssignmentOperator
      - name cannot be resolved to a variable
      - Syntax error on token &quot;:&quot;, invalid     AssignmentOperator
      - desc cannot be resolved to a variable
      - Syntax error on token &quot;:&quot;, invalid     AssignmentOperator
      - rating cannot be resolved to a variable
  </code></pre>