Skip to main content
David Cruz Anaya

David Cruz Anaya

Senior Android & Kotlin Multiplatform Engineer

  • Home
  • About
  • Portfolio
  • Book
  • Speaking
  • Blog
  • Flashcards
  • Nomad Life
  • Contact
Visit Vectencia Shop

Follow Me

Privacy Policy

2014 - 2026 © davthecoder is trading as Vectencia Ltd.

davthecoder
davthecoder.com
davthecoder × Vectencia
💉

Hilt Injection Bugs

Find the bugs in each code snippet

Shared ViewModel Scope1 P02 total
1/9
1@HiltViewModel
2class SharedCartViewModel @Inject constructor(
3 private val repository: CartRepository
4) : ViewModel() {
5
6 val cartItems = MutableStateFlow<List<CartItem>>(emptyList())
7
8 fun addItem(item: CartItem) {
9 cartItems.update { it + item }
10 viewModelScope.launch {
11 repository.syncCart(cartItems.value)
12 }
13 }
14
15 fun clearCart() {
16 cartItems.value = emptyList()
17 }
18}
19
20@AndroidEntryPoint
21class ProductFragment : Fragment() {
22 private val cartViewModel: SharedCartViewModel by viewModels()
23
24 fun onAddToCart(item: CartItem) {
25 cartViewModel.addItem(item)
26 }
27}
28
29@AndroidEntryPoint
30class CartFragment : Fragment() {
31 private val cartViewModel: SharedCartViewModel by viewModels()
32
33 fun onCheckout() {
34 // Process cart...
35 cartViewModel.clearCart()
36 }
37}
Click on the lines you think have bugsFound 0 of 2
←→NavigateAShow remainingRReset
🎯Bug Formula: What's wrong → What breaks for the user → The fix → The trade-off
Skip to main content
David Cruz Anaya

David Cruz Anaya

Senior Android & Kotlin Multiplatform Engineer

  • Home
  • About
  • Portfolio
  • Book
  • Speaking
  • Blog
  • Flashcards
  • Nomad Life
  • Contact
Visit Vectencia Shop

Follow Me

Privacy Policy

2014 - 2026 © davthecoder is trading as Vectencia Ltd.

davthecoder
davthecoder.com
davthecoder × Vectencia
💉

Hilt Injection Bugs

Find the bugs in each code snippet

Shared ViewModel Scope1 P02 total
1/9
1@HiltViewModel
2class SharedCartViewModel @Inject constructor(
3 private val repository: CartRepository
4) : ViewModel() {
5
6 val cartItems = MutableStateFlow<List<CartItem>>(emptyList())
7
8 fun addItem(item: CartItem) {
9 cartItems.update { it + item }
10 viewModelScope.launch {
11 repository.syncCart(cartItems.value)
12 }
13 }
14
15 fun clearCart() {
16 cartItems.value = emptyList()
17 }
18}
19
20@AndroidEntryPoint
21class ProductFragment : Fragment() {
22 private val cartViewModel: SharedCartViewModel by viewModels()
23
24 fun onAddToCart(item: CartItem) {
25 cartViewModel.addItem(item)
26 }
27}
28
29@AndroidEntryPoint
30class CartFragment : Fragment() {
31 private val cartViewModel: SharedCartViewModel by viewModels()
32
33 fun onCheckout() {
34 // Process cart...
35 cartViewModel.clearCart()
36 }
37}
Click on the lines you think have bugsFound 0 of 2
←→NavigateAShow remainingRReset
🎯Bug Formula: What's wrong → What breaks for the user → The fix → The trade-off