mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:51:18 +00:00
28c458b0f2
R=karlklose@google.com Review URL: https://codereview.chromium.org//15563003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22938 260f80e4-7a28-3924-810f-c04153c831b5
29 lines
695 B
Dart
29 lines
695 B
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
class B<T> {
|
|
}
|
|
|
|
class A<T> {
|
|
var field;
|
|
A(this.field);
|
|
asTypeVariable() => field as T;
|
|
asBOfT() => field as B<T>;
|
|
}
|
|
|
|
main() {
|
|
Expect.equals(42, new A<int>(42).asTypeVariable());
|
|
Expect.throws(
|
|
() => new A<String>(42).asTypeVariable(),
|
|
(e) => e is CastError);
|
|
|
|
var b = new B<int>();
|
|
Expect.equals(b, new A<int>(b).asBOfT());
|
|
Expect.throws(
|
|
() => new A<String>(b).asBOfT(),
|
|
(e) => e is CastError);
|
|
}
|