Kotlin issues (companion object)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với ví dụ Kotlin trong App_Resources/Android/src/main/java và dự án mẫu ns-android-kotlin.zip được liên kết. Chạy ứng dụng demo và kiểm tra đầu ra của console để tìm các trường companion-object, so sánh chúng với các trường và phương thức hoạt động được. Hoàn tất có nghĩa là các giá trị @JvmField và const có thể được truy cập từ NativeScript như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
- CLI: 8.6.5
- Cross-platform modules: 8.6.2
- Android Runtime: 8.6.1 (also 8.7.0-alpha.1)
- iOS Runtime (if applicable): -
- Plugin(s): -
Describe the bug
I tried to do some basic stuff with Kotlin stuff inside a NativeScript app (as I have no experience with Kotlin development) and I am experiencing some issues with companion objects.
I added this Kotlin file to App_Resources/Android/src/main/java
// KotlinTest.kt
package com.example
class KotlinTest {
val hello = "Hello from Kotlin!" //working
@JvmField
val instanceTestField : Int = 1234 //working
companion object {
@JvmStatic
fun increment(num: Int): Int { //working
return num + 1
}
@JvmField
val message : String = "Hi!" //not working
const val VERSION = 9 //not working
}
}
And I am trying to access the values like this in the NativeScript app:
const testObject = new com.example.KotlinTest();
console.log(testObject.hello); //working
console.log(testObject.instanceTestField); //working
console.log(com.example.KotlinTest.increment(5)); //working
console.log(com.example.KotlinTest.message); //not working
console.log(com.example.KotlinTest.VERSION); //not working
As far as I can read here about @JvmField annotation and here about const modifier this is valid Kotlin so it also shold work in NativeScript, but I always get undefined for those elements.
To Reproduce
Start the demo app provided below and check the logs in console.
Expected behavior
JvmFields and const values inside companion objects should be accessible in NativeScript.
Sample project
ns-android-kotlin.zip
Additional context
- Ngôn ngữ chính
- C++
- Star
- 563
- Fork
- 144
- Merge trung bình
- 10 giờ 46 phút
- Pull request đã merge (30 ngày)
- 14
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NativeScript/android
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
NativeScript/android#2039 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
NativeScript/android#2024 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
NativeScript/android#2020 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 42/100
NativeScript/android#2019 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
NativeScript/android#1986 ·
Tất cả issue của NativeScript/android
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
objectionary/eo-graphs#74 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
QuantStack/git2cpp#187 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100