Use a Library in the processor's generated classes

I'm developing a library to generate classes using annotations and processors. The generated classes should use Gson library from google. My question is : Where should I add the Gson dependency ? I'm currently adding it into the processor build.gradle but when the classes are generated, Gson is not found and Android Studio is suggesting to add it to the app module. build.gradle of t

在处理器生成的类中使用库

我正在开发一个库,使用注释和处理器来生成类。 生成的类应该使用谷歌的Gson库。 我的问题是: 我应该在哪里添加Gson依赖项? 我目前将它添加到处理器build.gradle中,但是当生成这些类时,找不到Gson,并且Android Studio建议将其添加到应用程序模块中。 处理器的 build.gradle : implementation project(':lib-annotation') implementation 'com.squareup:javapoet:1.9.0' implementation 'com.google.code.gson:gson:2

How do I declare a function parameter to accept functions that throw?

I have defined a function in Kotlin: fun convertExceptionToEmpty(requestFunc: () -> List<Widget>): Stream<Widget> { try { return requestFunc().stream() } catch (th: Throwable) { // Log the exception... return Stream.empty() } } I have defined a Java method with this signature: List<Widget> getStaticWidgets() throws IOException; I attemp

我如何声明一个函数参数来接受抛出的函数?

我在Kotlin中定义了一个函数: fun convertExceptionToEmpty(requestFunc: () -> List<Widget>): Stream<Widget> { try { return requestFunc().stream() } catch (th: Throwable) { // Log the exception... return Stream.empty() } } 我已经用这个签名定义了一个Java方法: List<Widget> getStaticWidgets() throws IOException; 我试图像这样编写它们: Strea

Why does this go into an infinite loop?

I have the following code: public class Tests { public static void main(String[] args) throws Exception { int x = 0; while(x<3) { x = x++; System.out.println(x); } } } We know he should have writen just x++ or x=x+1 , but on x = x++ it should first attribute x to itself, and later increment it. Why does x continue with 0 as value? --

为什么这会陷入无限循环?

我有以下代码: public class Tests { public static void main(String[] args) throws Exception { int x = 0; while(x<3) { x = x++; System.out.println(x); } } } 我们知道他应该只写x++或者x=x+1 ,但是在x = x++它应该首先将x赋给它自己,然后增加它。 为什么x继续0作为值? --update 这是字节码: public class Tests extends java.lang.Object{ publ

How do I run a Play Framework 2.1 project in IntelliJ?

I have an existing Play 2.1 project. I've been running it with the console and it works fine. However, when I try to run it with IntelliJ using these instructions it doesn't work: https://www.jetbrains.com/help/idea/getting-started-with-play-2-x.html#run_debug_playApp First I tried just running it by right clicking on the app and selecting "run play 2 app". It would not r

如何在IntelliJ中运行Play Framework 2.1项目?

我有一个现有的Play 2.1项目。 我一直在使用控制台运行它,它工作正常。 但是,当我尝试使用这些说明使用IntelliJ运行它时,它不起作用: https://www.jetbrains.com/help/idea/getting-started-with-play-2-x.html#run_debug_playApp 首先,我尝试通过右键单击应用程序并选择“run play 2 app”来运行它。 它不会运行,它给了我这个错误: sbt.IncompatiblePluginsException: Binary incompatibility in plugins detected.

multiple hashmaps pointing to the same key

I have multiple files which contains key=value string pairs. The keys are the same between the files, but the values differs. Each file can have 1000 plus of such pairs. I want to store each file in a separate hashmap, ie map<KeyString, ValueString> , so if there are five files, then there will be five hashmaps. To avoid duplicating the keys across each hashmap, is it possible to have

多个hashmaps指向相同的密钥

我有多个包含key = value字符串对的文件。 这些文件之间的密钥相同,但值不同。 每个文件可以有1000个这样的对。 我想将每个文件存储在一个单独的散列映射中,即map<KeyString, ValueString> ,因此如果有五个文件,则会有五个hashmaps。 为了避免在每个散列映射中重复键,是否可以让每个映射引用相同的键? 请注意,一旦密钥添加到地图中,它将不会被删除。 我考虑将第一个文件作为flyweight模式中的“基础”,这

ANTLR v4, JavaLexer and JavaParser returning null as parse tree

I am using antlr v4 for extracting parse tree of java programs for other purposes. I have started from this sample: ANTLR v4 visitor sample And I have tested the steps on given link to check if it works and everything gone right: java Run a = 1+2 b = a^2 c = a+b*(a-1) a+b+c ^Z Result: 33.0 And then I wrote my own to parse java programs as Structure below: |_Java.g4

ANTLR v4,JavaLexer和JavaParser返回null作为分析树

我使用antlr v4为其他目的提取Java程序的分析树。 我从这个样本开始:ANTLR v4访问者样本 我已经测试了给定链接上的步骤,以检查它是否正常工作,一切正常: java Run a = 1+2 b = a^2 c = a+b*(a-1) a+b+c ^Z Result: 33.0 然后我写下我自己的解析Java程序结构如下: |_Java.g4 |_Java.tokens

Is volatile expensive?

After reading The JSR-133 Cookbook for Compiler Writers about the implementation of volatile, especially section "Interactions with Atomic Instructions" I assume that reading a volatile variable without updating it needs a LoadLoad or a LoadStore barrier. Further down the page I see that LoadLoad and LoadStore are effectively no-ops on X86 CPUs. Does this mean that volatile read opera

是不稳定的昂贵?

阅读JSR-133编译器编写者手册,了解易失性的实现,尤其是“与原子指令的交互”部分我假设读取一个易失性变量而不更新它需要一个LoadLoad或一个LoadStore屏障。 在页面的下方,我看到LoadLoad和LoadStore在X86 CPU上是无效的。 这是否意味着可以在x86上执行易失性读取操作而无需显式高速缓存失效,并且与正常变量读取一样快(忽略易失性的重新排序约束)? 我相信我没有正确理解这一点。 有人可以照顾开导我吗? 编辑:我不

Difference between volatile and synchronized in Java

I am wondering at the difference between declaring a variable as volatile and always accessing the variable in a synchronized(this) block in Java? According to this article http://www.javamex.com/tutorials/synchronization_volatile.shtml there is a lot to be said and there are many differences but also some similarities. I am particularly interested in this piece of info: ... access to a v

Java中volatile和synchronized之间的区别

我想知道将变量声明为volatile且始终在Java中的synchronized(this)块中访问变量的区别? 根据这篇文章http://www.javamex.com/tutorials/synchronization_volatile.shtml有很多可以说,有很多的区别,但也有一些相似之处。 我对这条信息特别感兴趣: ... 对一个volatile变量的访问永远不会有阻塞的可能:我们只做过简单的读或写操作,所以与synchronized块不同,我们永远不会锁住任何锁; 因为访问一个volatile变量永远

Volatile piggyback. Is this enough for visiblity?

This is about volatile piggyback. Purpose: I want to reach a lightweight vars visibilty. Consistency of a_b_c is not important. I have a bunch of vars and I don't want to make them all volatile. Is this code threadsafe? class A { public int a, b, c; volatile int sync; public void setup() { a = 2; b = 3; c = 4; } public void sync() {

挥发性背驮式。 这对于可见度足够了吗?

这是关于不稳定的捎带。 目的:我想达到轻量级的可视性。 a_b_c的一致性并不重要。 我有一堆变数,我不想让它们全都变动。 这段代码是线程安全的吗? class A { public int a, b, c; volatile int sync; public void setup() { a = 2; b = 3; c = 4; } public void sync() { sync++; } } final static A aaa = new A(); Thread0: aaa.setup(); end Thread1:

Why Mockito can't mock a generic parameter type with number type in Kotlin?

We're moving our project to the Kotlin language. We decided to start from tests but faced with some strange behavior. Here is our test case: Service.java public final class Service { private final JdbcTemplate jdbcTemplate; public Service(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } public long check() { return jdbcTemplate.queryForO

为什么Mockito无法在Kotlin中使用数字类型嘲讽通用参数类型?

我们正在将我们的项目转移到Kotlin语言。 我们决定从测试开始,但面临一些奇怪的行为。 这是我们的测试用例: Service.java public final class Service { private final JdbcTemplate jdbcTemplate; public Service(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } public long check() { return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM table", Long.c