Exercise 2 - Json, Polymorphism, List#3
Open
VitorlFigueiredo wants to merge 3 commits intoexercise-2-polifrom
Open
Exercise 2 - Json, Polymorphism, List#3VitorlFigueiredo wants to merge 3 commits intoexercise-2-polifrom
VitorlFigueiredo wants to merge 3 commits intoexercise-2-polifrom
Conversation
…re as classes Restaurants e CoffeeShop, usando o conceito de polimorfismo para resolver o problema. Criei também uma função prettyPrint que verifica qual classe é, e exibi na tela conforme pedido.
roubertedgar
requested changes
Mar 20, 2024
|
|
||
| open class CommercialPlace( | ||
| val name: String, | ||
| val address: String, |
Contributor
There was a problem hiding this comment.
Address não é um objeto?
|
|
||
| val gson = Gson() | ||
|
|
||
| open class CommercialPlace( |
Contributor
There was a problem hiding this comment.
Pq não usou uma Interface ou abstract Class? Dá uma estudada nisso
Comment on lines
+40
to
+48
| fun prettyPrint(commercialPlace: List<CommercialPlace>) { | ||
| commercialPlace.forEach { commercialPlace -> | ||
| when (commercialPlace) { | ||
| is CoffeeShop -> println("Name: ${commercialPlace.name}, Rating: ${commercialPlace.rating}, Address: ${commercialPlace.address}") | ||
| is Restaurants -> println("Name: ${commercialPlace.name}, Address: ${commercialPlace.address} Rating: ${commercialPlace.rating},") | ||
| } | ||
|
|
||
| println() | ||
| } |
Contributor
There was a problem hiding this comment.
Essa função faz parte de alguma classe? Não... isso não é assim, estuda mais polimorfismo
| val json = jsonFile.readText() | ||
| //val listType = object : TypeToken<List<CommercialPlace>>() {}.type | ||
| //val commercialPlace: List<CommercialPlace> = gson.fromJson(json, listType) | ||
| val commercialPlace: List<CommercialPlace> = Gson().fromJson(json, Array<CommercialPlace>::class.java).toList() |
Contributor
There was a problem hiding this comment.
Como que vc sabe que um ComercialPlace é café ou restaurante no Json? Não estou vendo nada no jSon me contando isso.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Customized function to receive Restaurants and Cafeterias and print them, using the concept of polymorphism.