Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

How I can pass String to variable type URL? #4173

Closed
lukavucko opened this issue May 14, 2020 · 2 comments
Closed

How I can pass String to variable type URL? #4173

lukavucko opened this issue May 14, 2020 · 2 comments

Comments

@lukavucko
Copy link

Hi,
I got something like this:

interface Base {
var url: URL?
}

class BaseImpl: Base {
override var url: URL? = null
}

Now in my test I want to pass this:
url = "http://www.countries-list.info/Download-List/download.txt"
but of course I got this error:
^ Type mismatch: inferred type is String but URL? was expected

Does anyone knows how it should be solved?
I know that URL object accept string as parameter URL(String spec)
but I don't know how to implement that in my case.
Thank you in advance

@lukavucko lukavucko changed the title How to variable with type URL can consume String? How I can pass String to variable type URL? May 14, 2020
@artdfel
Copy link
Contributor

artdfel commented May 14, 2020

Hello! First of all, I got to remind you about Kotlin/Native issue tracker migration(see #4079). Bugs should be reported to the YouTrack, also one can ask for the community help on the #kotlin-native slack channel. Some known questions are answered on the StackOverflow, ask the new one can be done here.
About this particular question. As far as I can see, you're trying to use java.net.URL class, correct? This class is not available for Kotlin/Native. The whole point of Kotlin/Native is to provide programming with Kotlin but without JVM used. Therefore, no Java packages will be available for it.
If it's not Kotlin/Native, you can probably do something like url = URL(spec = "http://www.countries-list.info/Download-List/download.txt").

@lukavucko
Copy link
Author

Thank you for you answer, but I know that I can passed String in URL constructor. Thank you anyway, I will put the question on Stackoverflow.

@artdfel artdfel closed this as completed May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants