从 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);

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...