我正在关注https://github.com/Kotlin/dokka中的gradle插件部分。
我还在https://github.com/JetBrains/kotlin-examples/tree/master/gradle/dokka-gradle-example中尝试了dokka-gradle-example示例。
我使用的版本是:
android: '23.1.1'
dokka: '0.9.6'
gradle-android-plugin: '1.5.0'
kotlin: '1.0.0-rc-1036'
Run Code Online (Sandbox Code Playgroud)
但我也尝试使用0.9到0.9.7之间的Dokka版本。
输出的相关部分是:
...
:app:dokka FAILED
:app:dokka (Thread[Daemon worker Thread 9,5,main]) completed. Took 0.766 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:dokka'.
> com.intellij.mock.MockComponentManager.getPicoContainer()Lorg/picocontainer/MutablePicoContainer;
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:dokka'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) …Run Code Online (Sandbox Code Playgroud) 我将Kotlin与Vertx 3结合使用,有时我需要从公共URL的角度返回特定的URI,这与Vertx-Web请求认为我的URL的URL不同。这可能是由于我的负载均衡器或代理接收了一个URL,然后通过内部URL转发到我的应用程序。
因此,如果我这样做:
val publicUrl = context.request().absoluteURI()
Run Code Online (Sandbox Code Playgroud)
我最终得到一个URL http://10.10.103.22:8080/some/page而不是https://app.mydomain.com/some/page。该网址的所有内容都不对!
我发现了一个头,理应告诉我更多的原始请求,如X-Forwarded-Host但只包括app.mydomain.com或有时它的端口app.mydomain:80,但是这是不够找出网址的各个部分,我结束了像http://app.mydomain.com:8080/some/page这仍然是不正确的公共URL。
我还不仅需要处理我的当前URL,还需要处理对等URL,例如在同一服务器上的页面“ something / page1”上转到“ something / page2”。由于无法获得公共URL的重要部分,因此当我尝试解析为另一个URL时也提到了相同的问题。
我找不到Vertx-web中的方法来确定此公共URL,还是一些惯用的方法来解决此问题?
我使用Kotlin进行编码,因此该语言的任何示例都很棒!
注意: 这个问题是作者故意写和回答的(自我回答的问题),因此,有趣的问题的解决方案在SO中共享。
我上课了
class ThreadComment(
banned: Int,
closed: Int,
comment: String?,
date: String?,
email: String?,
files: ArrayList<File>?,
lasthit: Int,
name: String?,
num: String?,
op: Int,
parent: String?,
postsCount: Int,
sticky: Int,
subject: String?,
tags: String?,
timestamp: Int,
trip: String?) : Comment(banned, closed, comment, date, email, files, lasthit, name, num, op, parent, postsCount, sticky, subject, tags, timestamp, trip) {
val answers: ArrayList<String> = ArrayList()}
Run Code Online (Sandbox Code Playgroud)
父类看起来像
open class Comment(
@com.google.gson.annotations.SerializedName("banned")
val banned: Int = 0,
@com.google.gson.annotations.SerializedName("closed")
val closed: Int = 0,
@com.google.gson.annotations.SerializedName("comment")
val comment: …Run Code Online (Sandbox Code Playgroud) 使用 Amazon AWS Cognito Federated Identities并解析以下位置的数据时:
https://cognito-identity.amazonaws.com/.well-known/jwks_uri如下所示:
{"keys":[
{"kty":"RSA",
"alg":"RS512",
"use":"sig",
"kid":"ap-northeast-11",
"n":"AI7mc1assO5n6yB4b7jPCFgVLYPSnwt4qp2BhJVAmlXRntRZ5w4910oKNZDOr4fe/BWOI2Z7upUTE/ICXdqirEkjiPbBN/duVy5YcHsQ5+GrxQ/UbytNVN/NsFhdG8W31lsE4dnrGds5cSshLaohyU/aChgaIMbmtU0NSWQ+jwrW8q1PTvnThVQbpte59a0dAwLeOCfrx6kVvs0Y7fX7NXBbFxe8yL+JR3SMJvxBFuYC+/om5EIRIlRexjWpNu7gJnaFFwbxCBNwFHahcg5gdtSkCHJy8Gj78rsgrkEbgoHk29pk8jUzo/O/GuSDGw8qXb6w0R1+UsXPYACOXM8C8+E=",
"e":"AQAB"},
... }
Run Code Online (Sandbox Code Playgroud)
n使用以下代码(Kotlin 调用 JDK 8 Base64 类)可以很好地解码字段:
Base64.getDecoder().decode(encodedN.toByteArray())
Run Code Online (Sandbox Code Playgroud)
但是,当使用 Cognito用户池时,其 URL 中的数据格式如下:
https://cognito-idp.${REGION}.amazonaws.com/${POOLID}/.well-known/jwks.json
它具有相同类型的数据,但不会解码。相反,我最终会遇到以下错误:
非法的 base64 字符 5f
由于这是一个下划线_并且在Base64 URL字母表中,我尝试将解码更改为:
Base64.getUrlDecoder().decode(encodedN.toByteArray())
Run Code Online (Sandbox Code Playgroud)
但随后第一组数据将不再正确解码,因为它包含Base64 URL/编码的其他无效字符。
有没有一种方法可以使用jwks同一个解码器处理这两组数据?!?
注: 这个问题是作者特意写出来并回答的(自答问题),以便在SO中分享有趣问题的解决方案。
我正在尝试将一个侦听器从一个动作传递给一个类(一个适配器).
在java中(来自Action的代码):
private void setListeners() {
adapterRecyclerView.setListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SomeCodehere....
}
});
}
Run Code Online (Sandbox Code Playgroud)
(来自适配器的代码)
public void setListener(View.OnClickListener listener) {
this.listener = listener;
}
Run Code Online (Sandbox Code Playgroud)
有用.
现在我正试图转向kotlin.我首先翻译动作(将动作翻译为kotlin):
private fun setListeners() {
// !! is not fine i know
adapterRecyclerView!!.setListener { v ->
SomeCodehere....
}
}
Run Code Online (Sandbox Code Playgroud)
此时仍然有效.适配器的代码仍然在java和kotlin中的类的代码.现在我将适配器翻译为kotlin:
fun setListener(listener: View.OnClickListener) {
this.listener = listener
}
Run Code Online (Sandbox Code Playgroud)
现在它不起作用.Action没有编译.
错误:无法推断此参数"v"的类型.必需的View.OnClickListener.发现(???)单位.
我该怎么做演员?为什么将参数从kotlin传递给java工作,从kotlin传递给kotlin它不是?
我正在使用 Kotlin 开发一个 Web 应用程序来构建其前端。
我希望能够导入 npm 包,以便我可以在我的 Kotlin 代码中使用它们。我找不到有关如何执行此操作的示例。有关于如何从 Kotlin 生成 npm 包的示例,但没有关于如何在您的 Kotlin 代码中使用它们的示例。
如果我可以导入 Java 库,在我的 Kotlin 代码中使用它们并将其编译为 JavaScript,我也会很高兴,但这似乎还不可能,这就是我想导入 npm 代码的原因。
我想通过使用接口在 Kotlin 类中注入(丰富)行为和状态。像class Impl : Observable,其中 Observable 包含状态。
在 Scala 中使用 Traits(确实有效),为此寻找 Kotlin 解决方案:
object Test extends App {
val impl = new Impl()
val observer = new Observer()
impl.register(observer)
}
trait Observable {
// How to do this in Kotlin?
val observers = List()
def register(observer: Observer) {
observers.add(observer)
}
}
class Observer
class Parent
class Impl extends Parent with Observable
Run Code Online (Sandbox Code Playgroud)
在 Kotlin 中尝试(不起作用):
fun main(args: Array<String>) {
val impl = Impl()
val observer = Observer()
impl.register(observer) …Run Code Online (Sandbox Code Playgroud) 我只是想知道如果java具有与kotlin中的那些相同的arrayof()/ listof()/ setof()/ mapof()?如果没有,有没有办法同样工作?我发现它们与java非常不同.
顺便说一句,做intArrayOf()/ arraylistof()/ hashsetof()/ hashmapof()等做同样的事情int [] {}/new new ArrayList <>()/ new HashSet <>()/ new HashMap <> ()等?
我试图在 Spring 项目中使用 Kotlin,我发现实体扩展了抽象类。Kotlin 无法分辨抽象类中的注解。配置如下。
基地.kt
package io.qiyue.dream.entity
import org.hibernate.annotations.GenericGenerator
import org.springframework.data.annotation.CreatedBy
import org.springframework.data.annotation.LastModifiedBy
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime
import javax.persistence.Column
import javax.persistence.EntityListeners
import javax.persistence.GeneratedValue
import javax.persistence.Id
@EntityListeners(AuditingEntityListener::class)
abstract class Base {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id")
open var id: String? = null
@Column(name = "last_modified_at")
@LastModifiedDate
open val lastModifiedAt: LocalDateTime? = null
@Column(name = "last_modified_by")
@LastModifiedBy
open val lastModifiedBy: String? = null
@Column(name = "created_by")
@CreatedBy
open val createdBy: String? …Run Code Online (Sandbox Code Playgroud) data class MainPosts(val context: Context, val posts: Posts, val livePost: LivePosts?)
{
constructor() : this(null!!, null!!, null!!)
}
Run Code Online (Sandbox Code Playgroud)
嘿,我一直在试图弄清楚如何在Firebase的数据类上创建一个空的构造函数.
我尝试了上面的代码,但它没有正常工作.