Kotlin Newbie to Pro - CONSTRUCTOR AND FUNCTION OVERLOADING - Part 24

  Рет қаралды 17,194

Philipp Lackner

Philipp Lackner

Күн бұрын

Пікірлер: 35
@ananddangwal8424
@ananddangwal8424 Жыл бұрын
At 11:59 You can not use 'return maxArea( maxArea(shape 1 , shape 2) , shape 3) ' because maxArea(shape 1, shape 2) is returning 'Float' but the required parameter type for maxArea() function is "Shape".
@livebbott
@livebbott Жыл бұрын
Bhai kaha se padh raha hai poora course
@ananddangwal8424
@ananddangwal8424 Жыл бұрын
@@livebbott 'Kotlin newbie to pro' by Phillip lackner
@ananddangwal8424
@ananddangwal8424 Жыл бұрын
@@livebbott I also sometimes refer official documentation of Kotlin if I don't understand something. Baaki Chat Gpt toh hai hee doubts solve karne ke liye
@guy1407
@guy1407 4 жыл бұрын
time = 07:10 What you refer to you need to make "them" unique , is sometimes called the function "signature" meaning input parameters or output/return ones. For each implementation of the same function/method name, you must provide different input/output variable types or amount HTH
@dawiddebowski4346
@dawiddebowski4346 4 жыл бұрын
Will your comment (12:04) really work? maxArea takes two Shapes and returns Double, and in the second calling of the function you'll pass Double and Shape.
@dawiddebowski4346
@dawiddebowski4346 4 жыл бұрын
If the function returned Shape, it would have worked like that ;)
@PhilippLackner
@PhilippLackner 4 жыл бұрын
You're right, my bad, it should return shape in that case
@dawiddebowski4346
@dawiddebowski4346 4 жыл бұрын
@@PhilippLackner okok, thanks, I thought for a moment, that I messed something up 😅😅
@TheImaginativeSachin
@TheImaginativeSachin 2 жыл бұрын
it won't work i tried and failed😅
@str8busta
@str8busta 2 жыл бұрын
Was confused how he got the menu in 7:58 For anyone wondering it's Ctrl + P (Parameter info)
@ekkawutemeelugsana7068
@ekkawutemeelugsana7068 3 жыл бұрын
I think a much shorter way of this would be : Using Vararg I understand that this is for Constructor and Function overloading but this is a perfect use case for vararg right? Function overloading should be only be used when you have difference type of parameters isn't it? fun main() { val rect = Rectangle(5.0) val circle = Circle(3.0) val triangle = Triangle(7.0, 7.0, 7.0) println("The maximum area is ${maxArea(rect, circle, triangle)}") } fun maxArea(vararg shapes: Shape): Double { var maxArea = 0.0 shapes.forEach { when {it.area > maxArea -> { maxArea = it.area } } } return maxArea }
@ddnet_acclorite
@ddnet_acclorite Жыл бұрын
Thanks, but i wrote a little bit easier solution: fun maxArea(vararg shapes: Shape): Double{ var maxArea = 0.0 for (i in shapes) { if (maxArea
@ahmadosama2652
@ahmadosama2652 Жыл бұрын
Well done bro!
@opeyemicoker9104
@opeyemicoker9104 Жыл бұрын
cool, but he can't do that, because he hasn't talked about lambda functions
@opeyemicoker9104
@opeyemicoker9104 Жыл бұрын
cool, I did it using extension function and overloading
@rashmikataria3642
@rashmikataria3642 4 жыл бұрын
why it is necessary to call primary constructor explicitly inside secondary constructor? and also, secondary const. can run without primary constructor or not?
@rashmikataria3642
@rashmikataria3642 4 жыл бұрын
@Jundran Jones thankyou so much budd!
@frzkh4956
@frzkh4956 3 жыл бұрын
In the maxarea() function you choose the type of the shape1 parameter (Shape), what does this mean, Can you explain more? please. thank you
@AniobiStanley
@AniobiStanley Жыл бұрын
Shape is a class, and classes are blueprints for creating objects. The same way you could define parameter of type "Int" (since Int class is also a blueprint for creating objects), you can also define shape1 as an object of the Shape class.
@alh311
@alh311 Жыл бұрын
Hello Philipp, My only question is how are you doing?
@Lapakias
@Lapakias Жыл бұрын
Bro you are awesome!!!
@akanshakaushik4679
@akanshakaushik4679 2 жыл бұрын
If I add secondary constructor: constructor(diameter:Int): this(diameter/2) in Circle class, I am seeing an error "there's a cycle in the delegation calls chain". Not understanding why getting it as the primary constructor accept Double
@AniobiStanley
@AniobiStanley Жыл бұрын
In the "this()" part you have to define a relationship between the primary and the secondary constructors i.e. you should have something of the sort .toDouble
@gedalaarthika2497
@gedalaarthika2497 6 ай бұрын
Rectangle area should be high right? area=25.
@AniobiStanley
@AniobiStanley Жыл бұрын
fun printListItemsAlternating(list: List){ var i = 0 var j = list.size-1 var side = true //I used this variable to keep check of the side to pick from while (i
@bogite8734
@bogite8734 Жыл бұрын
Homework ( I looked up how to do the repeat() function ) fun main() { alternating(listOf(1, 2, 3, 4, 5)) alternating(arrayOf(1, 2, 3, 4, 5)) } /* * [1, 2, 3, 4, 5] * 1, 5, 2, 4, 3 * * [1, 2, 3, 4] * 1, 4, 2, 3 * */ fun alternating (obj: List) { var step = 0 var direction = "up" repeat(obj.size) { if(direction == "up") { println(obj[0+step]) direction = "down" } else if (direction == "down") { println(obj[(obj.size-1)-step]) direction = "up" step += 1 } } } fun alternating (obj: Array) { var step = 0 var direction = "up" repeat(obj.size) { if(direction == "up") { println(obj[0+step]) direction = "down" } else if (direction == "down") { println(obj[(obj.size-1)-step]) direction = "up" step += 1 } } }
@name1566
@name1566 2 жыл бұрын
i was thinking that huuhhhh.... i will end this series by 10 days but it will take atleast 20 days to complete amazing series on kotlin on yt
@AniobiStanley
@AniobiStanley Жыл бұрын
//Using Two Pointers Technique fun printListItemsAlternating(list: List){ var i = 0 var j = list.size-1 var side = true //I used this variable to keep check of the side to pick from while (i
@designart4928
@designart4928 5 жыл бұрын
make more video bro,👍
@Dawking.
@Dawking. 5 жыл бұрын
Thanksss!!
@AniobiStanley
@AniobiStanley Жыл бұрын
fun maxArea(shape1: Shape, shape2: Shape): Shape{ return if(shape1.area() > shape2.area()) shape1 else shape2 } fun maxArea(vararg shapes: Shape): Shape{ var max = 0.0 var maxShape : Shape = shapes[0] for (i in shapes){ if (i.area() > max) { max = i.area() maxShape = i } } return maxShape }
@jonievillejo6746
@jonievillejo6746 Жыл бұрын
fun main() { var myList = ListOf(1, 2, 3, 4, 5, 6, 7, 8) var myArray = arrayOf(1, 2, 3, 4, 5) reArranged(myList) reArranged(myArray) } fun reArranged(theList: List) { var low = 0 var high = theList.size - 1 var ctr = 0 println("List: " + theList) while ( low < high ) { println(theList[low]) println(theList[high]) low += 1 high -= 1 ctr += 1 } if (ctr != theList.count() && theList.count() % 2 != 0) println(theList[low]) } fun reArranged(theArray: Array) { var low = 0 var high = theArray.size - 1 var ctr = 0 println("Array: [${theArray.joinToString(", ")}]") while ( low < high ) { println(theArray[low]) println(theArray[high]) low += 1 high -= 1 ctr += 1 } if (ctr != theArray.count() && theArray.count() % 2 != 0) println(theArray[low]) } OUTPUT: List: [1, 2, 3, 4, 5, 6, 7, 8] 1 8 2 7 3 6 4 5 Array: [1, 2, 3, 4, 5] 1 5 2 4 3
@swaminathbera6407
@swaminathbera6407 3 жыл бұрын
liked calling maxArea() within maxArea() 😊
Kotlin Newbie To Pro - OBJECTS AND COMPANION OBJECTS - Part 25
12:42
Philipp Lackner
Рет қаралды 24 М.
Let, Also, Apply, Run, With - Kotlin Scope Functions
11:44
Philipp Lackner
Рет қаралды 100 М.
The Lost World: Living Room Edition
0:46
Daniel LaBelle
Рет қаралды 27 МЛН
Air Sigma Girl #sigma
0:32
Jin and Hattie
Рет қаралды 45 МЛН
Kotlin Newbie To Pro - VARARG, DEFAULT AND NAMED PARAMETERS -  Part 18
15:11
Kotlin Newbie to Pro - LAMBDA FUNCTIONS - Part 28
16:29
Philipp Lackner
Рет қаралды 35 М.
Kotlin Newbie to Pro - INHERITANCE - Part 21
15:07
Philipp Lackner
Рет қаралды 19 М.
Nothing is really cool in Kotlin
7:43
Sebastian Sellmair
Рет қаралды 8 М.
Kotlin Newbie to Pro - ANONYMOUS CLASSES - Part 26
11:51
Philipp Lackner
Рет қаралды 16 М.
Object - Kotlin Vocabulary
7:53
Android Developers
Рет қаралды 32 М.
Kotlin Newbie to Pro - EXCEPTIONS - Part 27
14:26
Philipp Lackner
Рет қаралды 13 М.
Constructors and Init blocks in Kotlin - BEST PRACTICES
5:33
Rahul Pandey
Рет қаралды 19 М.