Grails 版本:2.3.4
Java版本:1.7.0_79
我在一个独立应用程序中开发了一个到 AWS S3 的上传器,该应用程序是最新版本的 Grails。它正在工作,我现在一直在尝试将它实现到我较旧的 Grails 主应用程序中。
关于这行代码,我在服务器启动时遇到错误:
import grails.validation.Validateable
import org.springframework.web.multipart.MultipartFile
abstract class FeaturedImageCommand implements Validateable {
MultipartFile featuredImageFile
Long id
Long eventId
Integer version
static constraints = {
id nullable: false
version nullable: false
eventId nullable:false
featuredImageFile validator: { val, obj ->
if ( val == null ) {
return false
}
if ( val.empty ) {
return false
}
['jpeg', 'jpg', 'png'].any { extension -> // <1>
val.originalFilename?.toLowerCase()?.endsWith(extension)
}
}
}
}
错误内容如下:
在非抽象类中不能有抽象方法。必须将类“FeaturedImageCommand”声明为抽象类,或者必须实现方法“java.lang.Class.annotationType()”。
我假设我的 java 和 grails 版本导致了这种情况,但我真的希望有办法解决这个问题而不更新它们?
谢谢你。
最佳答案
嗯Validateable
是注解类型,annotationType()
方法来自Annotation
接口(interface),全部@interface
类型隐式继承。
(您的代码……奇怪。为什么要将注释“实现”为一个类?我的理解是您将无法使用定义为 @interface
子类的类作为注释.. .)
implements
的类(class)一个 @interface
那么您将需要实现该方法。 (而且我不知道你是如何摆脱以前不这样做的。Validateable
在我可以在 Grepcode 网站上看到的所有版本中都是 @interface
。)关于java - Grails:在非抽象类中不能有抽象方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43393839/