例如:
Java的:
public class Foo {
public int getSomething() {
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
科特林:
class Bar : Foo() {
// works
override fun getSomething() = 2
// doesn't work ('something' overrides nothing)
// override val something = 2
}
Run Code Online (Sandbox Code Playgroud)
我认为这val something = 2将转换为public int getSomething() { return 2; }Java字节码.
我有一个类似于以下的类:
@Configuration
public class ApplicationConfiguration {
private <T> T createService(Class<T> serviceInterface) {
// implementation omitted
}
@Bean
public FooService fooService() {
return createService(FooService.class);
}
@Bean
public BarService barService() {
return createService(BarService.class);
}
...
}
Run Code Online (Sandbox Code Playgroud)
问题是有太多@ Bean-annotated方法,它们的名称,返回类型和crateService方法调用的参数不同.我想使这个类类似于以下内容:
@Configuration
public class ApplicationConfiguration {
private static final Class<?>[] SERVICE_INTERFACES = {
FooSerivce.class, BarService.class, ...};
private <T> T createService(Class<T> serviceInterface) {
// implementation omitted
}
@Beans // whatever
public Map<String, Object> serviceBeans() {
Map<String, Object> result = ...
for (Class<?> serviceInterface : …Run Code Online (Sandbox Code Playgroud) Gradle 5.0、Kotlin DSL
创建gradle.properties文件:
kotlinVersion=1.3.10
Run Code Online (Sandbox Code Playgroud)
创建build.gradle.kts文件:
val kotlinVersion: String by project
println(kotlinVersion) // works
plugins {
kotlin("jvm").version(kotlinVersion)
// ^ Unresolved reference: kotlinVersion
}
repositories {
jcenter()
}
tasks.register("compute") {
doLast {
println(kotlinVersion) // works
}
}
Run Code Online (Sandbox Code Playgroud)
运行gradle compute,然后更改
kotlin("jvm").version(kotlinVersion)
Run Code Online (Sandbox Code Playgroud)
到
kotlin("jvm").version("1.3.10")
Run Code Online (Sandbox Code Playgroud)
然后再次运行。一切正常。
我只是做错了什么吗?或者这是某种限制或错误?
我只是想将 Kotlin 版本移出构建脚本,这样我就可以稍后更改它(例如通过命令行... -PkotlinVersion=1.3.0),并保持依赖项和插件相同。
我正在使用 Spring 4.1.2,并且有以下代码:
public class Foo {
}
public class Bar {
}
public interface Service<T> {
}
@Service("fooService")
public class FooServiceImpl implements Service<Foo> {
}
@Service("barService")
public class BarServiceImpl implements Service<Bar> {
}
Run Code Online (Sandbox Code Playgroud)
我知道 Spring 4 可以注入通用 bean 实例,如下所示:
@Autowired
private Service<Foo> service; // works fine
Run Code Online (Sandbox Code Playgroud)
但我需要以静态方式获取它们,如下所示:
Service<Foo> service = getService(getContext(), Foo.class);
...
public static <T> Service<T> getService(ApplicationContext context,
Class<T> objectClass) {
...
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用ApplicationContext.getBeansOfType(Service.class),但它返回所有可用的 bean 实例(fooService和barService)。所以我需要以某种方式传递类型参数。
有什么办法可以做到这一点吗?像这样的东西:
@SupressWarnings("unchecked")
Service<Foo> service = applicationContext.getGenericBean( …Run Code Online (Sandbox Code Playgroud) 我希望我的 Kotlin 导入语句按照与 Java 相同的规则进行排序(“编辑器”?“代码样式”?“Java”?“导入”?“导入布局”),但似乎 IDE 完全忽略了它们Kotlin 源文件。另外,我没有找到 Kotlin 的类似设置(“导入”选项卡上没有“导入布局”)。
有什么办法可以拥有它们吗?(IntelliJ IDEA 2018.3.5 终极版)
我正在使用Delphi 2007,我有这样的情况:
{ CommonUnit.pas }
type
// there is a callback which I want to process
TFooBar = procedure(Sender: IInterface) of object; stdcall;
// there is an interface which is used by all modules
IFoo = interface
['{0FAA4B2B-E82A-4A2A-B55F-C75EC53A1318}']
procedure Bar(Callback: TFooBar); stdcall;
end;
{ UnitInModuleCompiledWithoutPackages.pas }
type
// there is a class which implements IFoo
// and it's defined in Module One compiled without packages
TFoo = class(TInterfacedObject, IFoo)
public
// implementation is ommited
procedure Bar(Callback: TFooBar); stdcall;
end;
{ …Run Code Online (Sandbox Code Playgroud) 我有以下路由定义文件:
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<setHeader headerName="from">
<constant>user@mailserver.com</constant>
</setHeader>
<setHeader headerName="to">
<constant>john.smith@acme.com</constant>
</setHeader>
<setHeader headerName="subject">
<constant>Hello</constant>
</setHeader>
<setHeader headerName="contentType">
<constant>text/plain;charset=UTF-8</constant>
</setHeader>
<setBody>
<constant>Test</constant>
</setBody>
<!-- <attachment id="attachment.zip" uri="resource:file:test.zip"/> -->
<to uri="smtp://user@mailserver.com?password=secret"/>
</route>
</routes>
Run Code Online (Sandbox Code Playgroud)
可以使用Java DSL发送带附件的电子邮件:
Endpoint endpoint = camelContext.getEndpoint(
"smtp://user@mailserver.com?password=secret");
Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
Map<String, Object> headers = new HashMap<>();
headers.put("from", "user@mailserver.com");
headers.put("to", "john.smith@acme.com");
headers.put("subject", "Hello");
headers.put("contentType", "text/plain;charset=UTF-8");
in.setHeaders(headers);
in.setBody("Test");
in.addAttachment("attachment.zip", new DataHandler(
applicationContext.getResource("file:test.zip").getURL()));
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
Run Code Online (Sandbox Code Playgroud)
但我需要仅使用XML DSL执行此操作.
在Camel有什么办法吗?
我path.data为我的 Elasticsearch 集群配置了多个。\n官方文档指出,单个分片仅使用单个路径,因此它永远不会拆分到多个路径上。\n我想找到一种方法来找出哪个路径在哪个节点用于某些特定分片(主分片或副本分片),例如索引 my-index 主分片 0 \xe2\x86\x92节点 RQzJvAgLTDOnEnmIjYU9FA 路径 /mnt/data1。试过了/_nodes,,,/_stats/_segments/_shard_stores但没有任何对路径的