代码@TypeConverterAnnotation是什么意思?

时间:2017-08-04 07:59:44

标签: android kotlin

以下代码来自网页,我无法理解代码@TypeConverterAnnotation是什么意思?

它只是一个注释,我可以删除代码吗?

package mobi.porquenao.poc.kotlin.core

import com.raizlabs.android.dbflow.converter.TypeConverter
import java.util.*
import com.raizlabs.android.dbflow.annotation.TypeConverter as TypeConverterAnnotation

@TypeConverterAnnotation
class CalendarConverter : TypeConverter<Long, Calendar>() {

    override fun getDBValue(model: Calendar): Long? {
        return model.timeInMillis
    }

    override fun getModelValue(data: Long?): Calendar {
        val calendar = Calendar.getInstance()
        calendar.timeInMillis = data!!
        return calendar
    }

}

1 个答案:

答案 0 :(得分:4)

是的,来自 DBFlow project 注释:

/**
 * Author: andrewgrosner
 * Description: Marks a class as being a TypeConverter. 
 * A type converter will turn a non-model, non-SQLiteTyped class into
 * a valid database type.
 */
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
public @interface TypeConverter {

    /**
     * @return Specify a set of subclasses by which the {@link TypeConverter} 
     * registers for. For each one, this will create a new instance of the converter.
     */
    Class<?>[] allowedSubtypes() default {};
}

我们如何知道您的代码中是否需要它? :)