GOLANG_GOOGLE Telegram 2846
Вопрос:

Что будет выведено на экран?


Напишите полный вывод программы и объясни, почему именно так.


package main

import (
"fmt"
"time"
)

type Speaker interface {
Speak() string
}

type Person struct {
name string
}

func (p Person) Speak() string {
return "Hi, I'm " + p.name
}

func main() {
var s Speaker
p := Person{name: "Alice"}
s = p

p.name = "Bob"

fmt.Println(s.Speak()) // (1)

func() {
s := p // shadowing: s — это теперь Person, а не Speaker
fmt.Println(s.Speak()) // (2)
}()
go func(p Person) {
time.Sleep(10 * time.Millisecond)
fmt.Println(p.Speak()) // (3)
}(p)

p.name = "Charlie"

time.Sleep(20 * time.Millisecond)
}


💡Подсказки:
Что происходит с интерфейсами в Go при присвоении структур?

Что такое shadowing и как это влияет на s внутри анонимной функции?

Как работает передача аргументов в goroutine?

Как изменения структуры после передачи влияют на уже переданные значения?



Ответ:

Hi, I'm Alice
Hi, I'm Bob
Hi, I'm Bob


@golangtests



tgoop.com/Golang_google/2846
Create:
Last Update:

Вопрос:

Что будет выведено на экран?


Напишите полный вывод программы и объясни, почему именно так.


package main

import (
"fmt"
"time"
)

type Speaker interface {
Speak() string
}

type Person struct {
name string
}

func (p Person) Speak() string {
return "Hi, I'm " + p.name
}

func main() {
var s Speaker
p := Person{name: "Alice"}
s = p

p.name = "Bob"

fmt.Println(s.Speak()) // (1)

func() {
s := p // shadowing: s — это теперь Person, а не Speaker
fmt.Println(s.Speak()) // (2)
}()
go func(p Person) {
time.Sleep(10 * time.Millisecond)
fmt.Println(p.Speak()) // (3)
}(p)

p.name = "Charlie"

time.Sleep(20 * time.Millisecond)
}


💡Подсказки:
Что происходит с интерфейсами в Go при присвоении структур?

Что такое shadowing и как это влияет на s внутри анонимной функции?

Как работает передача аргументов в goroutine?

Как изменения структуры после передачи влияют на уже переданные значения?



Ответ:

Hi, I'm Alice
Hi, I'm Bob
Hi, I'm Bob


@golangtests

BY Golang


Share with your friend now:
tgoop.com/Golang_google/2846

View MORE
Open in Telegram


Telegram News

Date: |

5Telegram Channel avatar size/dimensions It’s yet another bloodbath on Satoshi Street. As of press time, Bitcoin (BTC) and the broader cryptocurrency market have corrected another 10 percent amid a massive sell-off. Ethereum (EHT) is down a staggering 15 percent moving close to $1,000, down more than 42 percent on the weekly chart. The court said the defendant had also incited people to commit public nuisance, with messages calling on them to take part in rallies and demonstrations including at Hong Kong International Airport, to block roads and to paralyse the public transportation system. Various forms of protest promoted on the messaging platform included general strikes, lunchtime protests and silent sit-ins. There have been several contributions to the group with members posting voice notes of screaming, yelling, groaning, and wailing in different rhythms and pitches. Calling out the “degenerate” community or the crypto obsessives that engage in high-risk trading, Co-founder of NFT renting protocol Rentable World emiliano.eth shared this group on his Twitter. He wrote: “hey degen, are you stressed? Just let it out all out. Voice only tg channel for screaming”. Activate up to 20 bots
from us


Telegram Golang
FROM American