-1

getインターフェイスでリクエストを行いRequestSpecification、パラメーター化された を返したい場合List<T>、メソッドで何をしなければなりません.as()か??? ハイライトボールドです!おそらく、リストの実装の 1 つを指定する必要がありますか? しかし、私は特定のパラメータ化が必要Listです!

List<> response = given().parameter(x,x)
                   .expect()
                   .statuscode(200)
                   .when()
                   .get("some kind of GET")
                   **.as(List<>.class)**
4

2 に答える 2

2

Welcome to type erasure. All lists are the same at runtime. Unless you have the type information of the parameter type as a class object, all you can do is:

@SuppressWarnings("unchecked")
List<DesiredType> response = (List<DesiredType>)given().parameter(x,x)
               .expect()
               .statuscode(200)
               .when()
               .get("some kind of GET")
               .as(List.class);

Be aware though that if this puts in objects that are not of type DesiredType, you will encounter problems when accessing that list later on.

于 2013-05-14T15:32:16.047 に答える