2424
2525import com .google .protobuf .InvalidProtocolBufferException ;
2626import java .util .ArrayList ;
27+ import java .util .Collections ;
2728import java .util .Iterator ;
2829import java .util .LinkedHashMap ;
2930import java .util .List ;
@@ -173,8 +174,8 @@ private Result(List<Tensor<?>> results, List<Output<?>> fetches, RunMetadata met
173174 }
174175
175176 this .metadata = metadata ;
176- this .results = new ArrayList <>( results ) ;
177- this .fetches = new ArrayList <>( fetches ) ;
177+ this .results = results ;
178+ this .fetches = fetches ;
178179 outputMap = new LinkedHashMap <>();
179180 for (int i = 0 ; i < fetches .size () ; i ++){
180181 outputMap .put (fetches .get (i ), results .get (i ));
@@ -192,21 +193,21 @@ private void requireOpen(){
192193 */
193194 public List <Tensor <?>> getResults () {
194195 requireOpen ();
195- return new ArrayList <> (results );
196+ return Collections . unmodifiableList (results );
196197 }
197198
198199 /**
199200 * Get the outputs that were fetched.
200201 */
201202 public List <Output <?>> getFetches () {
202- return new ArrayList <> (fetches );
203+ return Collections . unmodifiableList (fetches );
203204 }
204205
205206 /**
206207 * Get a map of the fetched outputs to their results.
207208 */
208209 public Map <Output <?>, Tensor <?>> getOutputMap (){
209- return new LinkedHashMap <> (outputMap );
210+ return Collections . unmodifiableMap (outputMap );
210211 }
211212
212213 /**
@@ -591,7 +592,7 @@ private Result runHelper(boolean wantMetadata) {
591592 } finally {
592593 runRef .close ();
593594 }
594- return new Result (outputs , this .outputs , metadata );
595+ return new Result (outputs , new ArrayList <>( this .outputs ) , metadata );
595596 }
596597
597598 private class Reference implements AutoCloseable {
0 commit comments