Tag: Java

如何添加kotlin类到gradle JavaCompile任务

我用spring引导来使用kotlin和java来开发我的项目。 我的构建工具是gradle,一个任务定义如下: configurations { providedRuntime jpametamodel } dependencies { jpametamodel (‘org.hibernate:hibernate-jpamodelgen:4.3.11.Final’) } task generateMetaModel(type: JavaCompile, group: ‘build’, description: ‘metamodel generate’) { source = sourceSets.main.java classpath = configurations.compile + configurations.jpametamodel options.compilerArgs = [“-proc:only”] destinationDir = sourceSets.generated.java.srcDirs.iterator().next() doFirst { delete(sourceSets.generated.java.srcDirs) } } 这个任务适用于kotlin类,但是如果我添加kotlin类,任务不能通过抛出以下错误: Hibernate JPA 2 Static-Metamodel Generator 4.3.11.Final /…/src/main/java/com/app/web/rest/UserResource.java:18: Cannot find ….. import com.app.web.rest.dto.SimpleUser; ^ Symbol: […]

如何滚动到RecyclerView的底部? scrollToPosition不起作用

我想在加载活动后滚动到RecyclerView列表的底部。 GENERIC_MESSAGE_LIST = (ArrayList) intent.getExtras().getParcelableArrayList(ConversationsAdapter.EXTRA_MESSAGE); conversationView = (RecyclerView) findViewById(R.id.list_messages); conversationView.setHasFixedSize(true); conversationViewLayoutManager = new LinearLayoutManager(this); conversationView.setLayoutManager(conversationViewLayoutManager); conversationViewAdapter = new ConversationAdapter(GENERIC_MESSAGE_LIST, this); conversationView.setAdapter(conversationViewAdapter); conversationView.scrollTo(…)抛出一个关于在RecyclerView中不被支持的exception,而conversationView.scrollToPosition(…)似乎没有做任何事情。 上面的代码块后,我补充说 conversationView.scrollToPosition(GENERIC_MESSAGE_LIST.size() + 1) 这不起作用。 GENERIC_MESSAGE_LIST有30个元素。

无论如何,我可以阻止推送通知显示在客户端?

我正在使用UrbanAirship进行推送通知。 一切工作正常,但有一些情况下,我不希望显示来自城市的推送通知。 我必须在服务器端处理这个问题,还是可以在客户端处理? 如果可能的话,我将如何在客户端处理这个问题? 我已经尝试取消通知,并且工作,但它仍然在状态栏中显示翻转消息。

如何从Kotlin的Javatypes数组中获取javaclass?

对于pojo类: //java MyClass.getClass(); //kotlin MyClass::class.java 但如何从数组getClass? //java MyClass[].class; //kotlin ??? MyClass[]::class.java – 不工作:(

如果根对象中的简单属性发生更改,则JaVers会检测子级中的更改

我使用Kotlin,我试图用JaVers比较两个复杂的对象(多个周期)。 这些对象使用多个Id-属性。 因此,我创建了Id-Classes,为每个类都有一个Id-Property。 在Id-Classes中,我也使用对根对象的引用,因为我需要使用它们来为我的数据库创建主键。 当我比较两个对象和根对象中的一个更改时,JaVers应该只列出一个ValueChange。 但是相反,JaVers发现了5个改变(NewObject-child,ObjectRemoved-child,ReferenceChanged-child,ListChange-root,ValueChanged-root)。 试图解决这个问题,我更新了我的equals和hashCode方法的子对象来检查根对象的id而不是根对象本身当计算相等==> root1.childList == root2.childList返回true 。 任何想法,我可以教JaVers没有任何儿童对象已经改变? League.kt – 根对象 @Entity data class League(@EmbeddedId val leagueId: LeagueId? = null, var name: String? = null, var region: String? = null, @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true) var groups: List? = null, @OneToMany(cascade = [CascadeType.ALL], orphanRemoval = true) var matchDays: List? = […]

尽量减少class级中的代码重复?

我正在使用下面的类通过使用套接字发送数据到我们的消息队列以同步的方式或异步的方式,如下所示。 到目前为止,我在下面的课程中复制了很多代码。 我有以下5个方法用于同步或异步发送数据,我相信可能有更好的方法来重写这些方法。 public class SendRecord { private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2); private final Cache cache = CacheBuilder .newBuilder() .maximumSize(2000000) .concurrencyLevel(100).build(); private static class Holder { private static final SendRecord INSTANCE = new SendRecord(); } public static SendRecord getInstance() { return Holder.INSTANCE; } private SendRecord() { executorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { […]

如何用一个复合types的数组来调用postgres函数

我正在寻找如何调用具有参数的复合types的postgres函数的建议。 问过类似的问题,但我find了一个满意的答案。 我有以下复合types: CREATE TYPE collect.event_record AS ( event_type integer , event_timestamp timestamp without time zone , event_data text , event_import_id integer ); 我有以下function: CREATE OR REPLACE FUNCTION collect.insert_events( fail_on_duplicates boolean, source_public_id text, event_records collect.event_record[]) RETURNS integer AS … 在postgres方面一切似乎工作正常。 现在我只需要从java / kotlin中调用它。 我们使用这个版本的postgres驱动程序: compile group: “org.postgresql”, name: “postgresql”, version: “9.4.1212” 在PreparedStatement有一个方法,似乎是我在找什么: void setArray (int […]

如何将一个函数应用于列表的列表

我知道flatMap操作,但不完全明白它是如何工作的。 我有一个class级: class Days() { List dates; } 然后我有这些对象的列表 List month 我想对这个对象中的每一个日期做一些事情(例如把它们转换成一个字符串),然后找回所有这些字符串的单个列表。 如何做到这一点?

Android N Java 8function(Jack编译器)和Kotlin互操作

更新3. KOTLIN 现在正式支持 Android的发展 。 通过GOOGLE。 YAAAAAAAAS! 更新2 :它看起来像JetBrains是真的承诺从长远来看支持Android的Kotlin 。 我是一个快乐的kotlin用户:)。 更新 :JetBrains的Hadi Hariri 提到他们将发布关于这个主题的一些信息 。 一旦他们这样做,我会更新这个post。 ===弃置的东西下一个=== Google刚刚发布了即将推出的Android N预览版,其中包括一些有趣的function,其中最引人注目的是部分Java 8语言支持 。 这可能是由于Google正在开发的新Jack工具链造成的。 当前使用javac或kotlinc的工具链: javac ( .java – > .class ) – > dx ( .class – > .dex ) kotlinc ( .kt – > .class ) – > dx ( .class – > .dex […]

在kotlin的Math类中添加一个扩展函数

我在Kotlin的Math类中增加了一个函数,但是我不能使用它,我之前用MutableList做了这个, MutableList它的工作,但是我不能用Math类来完成。 fun Math.divideWithSubtract(num1: Int, num2: Int) = Math.exp(Math.log(num1.toDouble())) – Math.exp(Math.log(num2.toDouble()))