问题描述
我有一个这样定义的类(伪代码):
I have a class defined like so (pseudo code):
package com.some.namespace
public class SomeClass {
protected SomeClass() {}
// stuff...
public class SomeInnerClass {
public SomeInnerClass() {}
// more stuff (accesses instance variables from SomeClass)...
}
}
然后在模板中,我使用可重用的块定义,如下所示:
Then in my template I use the reusable block defines like so:
@doSomething(val: com.some.namespace.SomeClass.SomeInnerClass) = {
// even more stuff...
}
但是我得到了错误:
我无法访问模板中的内部类吗?还是应该这样做? (如果应该可以,我可能需要发布实际的代码)
Am I not able to access inner classes within the templates or is this supposed to work? (if it is supposed to work I might need to post my actual code)
推荐答案
它应该可以工作,但是由于SomeInnerClass
是依赖的类型,即依赖于您的单例外部类实例,因此您需要像这样写:
It should work, but because SomeInnerClass
is a dependent type, i.e. dependent on your singleton outer class instance, you need to write it like:
@doSomething(value: com.some.namespace.SomeClass#SomeInnerClass) = {
// even more stuff...
}
Scala中的SomeClass#SomeInnerClass
语法含糊地表示 SomeClass
的任何实例中的SomeInnerClass
.有关更多详细信息,请参见此答案.
The SomeClass#SomeInnerClass
syntax in Scala means, vaguely, a SomeInnerClass
from any instance of SomeClass
. See this answer for more detail.
但是,如果内部类是 static ,那么您当前的SomeClass.SomeInnerClass
语法将是解决之道.
If the inner class was static, however, your current SomeClass.SomeInnerClass
syntax would be the way to go.
这篇关于Play框架(2.3.5)-访问内部类的模板失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!