kotlin dagger injection - Android

Table of Contents

想請教一個dagger injection 的問題

目前是寫espresso test, 要注入一個isTabletEnabled參數

這樣寫

@Inject @Identifier boolean isTabletEnabled

這樣在java file 當中沒有問題

但是copy 到kotlin 檔案中被轉成

@Inject @Identifier internal var isTabletEnabled: Boolean = false

編譯會過, 但是在執行時會跑出can't inject to private field 錯誤,

stackoverflow 上面看到是教人用constructor injection

但我這是跑test, class & method 都不能有參數

想請問看看有沒有人有甚麼想法

--

All Comments

Doris avatarDoris2016-05-31
應該要去AndroidDev板