微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 class<T> 中提取 T 并在类构建中使用 T

如何解决从 class<T> 中提取 T 并在类构建中使用 T

我想使用我从 MyView hex = new MyView(this,yellow,10,90); doodleView.addView(hex); Path hexPath = new Path(); hexPath.moveto(10,10); hexPath.lineto(10,PHONE_Dims.y *4/5); // you've already moved to this position with the above lineto() call // hexPath.moveto(10,PHONE_Dims.y *4/5); // Animate the x and y properties,not startX and startY ObjectAnimator hexAn = ObjectAnimator.ofFloat(hex,"x","y",hexPath); OvershootInterpolator interpolator = new OvershootInterpolator(); hexAn.setInterpolator(interpolator); hexAn.setDuration(5000); hexAn.start(); 得到的 Class<T> 并用它在类中构建一个类型为 T 的变量。我不太确定如何描述它,所以这里有一些代码,希望能够很好地描述它。

Type.resolveClass()

所以我想知道如何从 public static function build(name:String) { var fields = Context.getBuildFields(); // Get Class<T> var resolved = Type.resolveClass(name); // Do some magic to get a ComplexType that represents the T in Class<T> var type = magic(resolved); // I want to find out how to do this // Create a field of type T fields.push({ name: "ofTypeName",pos: Context.currentPos(),access: [AStatic,APublic],kind: FVar(type,macro null) }); return fields; } 中得到一个 ComplexType 代表 Class<T>

解决方法

var type = Context.getType(name);
var ctype = TypeTools.toComplexType(type);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。