Jump to content

Kotlin, pass in the resource ID as integer but it contains alphabet letter

JoneLoveIT

why pass in the resource ID as integer but it contains alphabet letter? i dont understand it dont get any error. As i have learnt that string can be used for "abc" or "abc123", while int can only be used for "123"

image.png.e2b1f04ee451cab54c9a57aa4723dc80.png

image.png.4849dc2c5b8bceccc0e0b2a76070d032.png

 

Link to comment
Share on other sites

Link to post
Share on other sites

R.string.* is a reference to an integer that points to your actual String.

HAL9000: AMD Ryzen 9 3900x | Noctua NH-D15 chromax.black | 32 GB Corsair Vengeance LPX DDR4 3200 MHz | Asus X570 Prime Pro | ASUS TUF 3080 Ti | 1 TB Samsung 970 Evo Plus + 1 TB Crucial MX500 + 6 TB WD RED | Corsair HX1000 | be quiet Pure Base 500DX | LG 34UM95 34" 3440x1440

Hydrogen server: Intel i3-10100 | Cryorig M9i | 64 GB Crucial Ballistix 3200MHz DDR4 | Gigabyte B560M-DS3H | 33 TB of storage | Fractal Design Define R5 | unRAID 6.9.2

Carbon server: Fujitsu PRIMERGY RX100 S7p | Xeon E3-1230 v2 | 16 GB DDR3 ECC | 60 GB Corsair SSD & 250 GB Samsung 850 Pro | Intel i340-T4 | ESXi 6.5.1

Big Mac cluster: 2x Raspberry Pi 2 Model B | 1x Raspberry Pi 3 Model B | 2x Raspberry Pi 3 Model B+

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, jj9987 said:

R.string.* is a reference to an integer that points to your actual String.

Does that mean it is always int?

it is wrong when it is

- data class Affirmation(val stringResourceId: Double)

- data class Affirmation(val stringResourceId: String)

Link to comment
Share on other sites

Link to post
Share on other sites

15 minutes ago, JoneLoveIT said:

it is wrong when it is

- data class Affirmation(val stringResourceId: Double)

- data class Affirmation(val stringResourceId: String)

Yes, because resource IDs are always stored as integers even if they reference a string or a double.

 

You should work on your understanding of the difference between a variable and an inline string... in most programming languages, if you want to type out a string value you need to enclose it in quotation marks (" or '). Otherwise it's interpreted as a variable name. On the other hand, pure numbers are typically assumed to be values and not variable names.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×