But there's another way I might have implemented this getFriends method. I
could just add a toString method to the Person class. If the toString method
returns the name, then I could implement getFriends the way I did before. So
here's approximately what I had before, and if I run the tester again, I can
see that the getFriends method is working. This is because when I called
toString on the arraylist of Friends, it uses each friend's toString method, to
get it's name. Well, actually just to get a representation of it, which in this
case, is the name. This implementation will work, so long as I don't want the
person to return something more than the name, in its toString method.
Pero hay otra manera en que podría haber implementado este método getFriends. Podría
tan solo haber añadido un método toString a la clase Persona. Si el método toString.
devuelve el nombre, entonces podría implementar getFriends como lo hice antes. Así pues,
esto es aproximadamente lo que tenía antes, y si ejecuto el probador de nuevo, puedo
ver que el método getFriends está funcionando. Esto es porque cuando llamé a
toString en la ArrayList de Amigos, utiliza el método toString de cada amigo para
obtener su nombre. Bueno, en realidad sólo para obtener una representación del mismo que, en este
caso, es el nombre. Esta aplicación va a funcionar, mientras yo no quiera que
Persona devuelva algo más que el nombre, en su método toString.
Mais il y a une autre façon d'implémenter
cette méthode getFriends.
Je pourrais simplement ajouter
une méthode toString à la classe Person.
Si la méthode toString renvoie le nom,
alors je pourrais implémenter
getFriends comme avant.
Voici à peu près ce que
j'avais auparavant,
et si je relance le testeur, je peux voir
que la méthode getFriends fonctionne.
C'est parce que quand j'ai appelé
toString sur le vecteur des amis,
il utilise la méthode toString de
chaque ami, pour obtenir son nom,
en fait juste pour en avoir
une représentation,
qui dans ce cas, est le nom.
Cette implémentation fonctionnera,
tant que je ne veux pas
que la personne renvoie
quelque chose de plus que le nom,
dans sa méthode toString.
このgetFriendsメソッドのもう1つの実装方法は
toStringメソッドを
Personクラスに追加するというものです
toStringメソッドが名前を返すなら
以前の方法でgetFriendsを実装できます
これはほぼ前のものと同じです
テスターの実行で
getFriendsメソッドが機能しているのが分かります
なぜならtoStringを
friendsのArrayListに呼び出した時
getFriendsメソッドは名前を得ようと
それぞれの友人のtoStringメソッドを使うためです
実際は表現を得るためですが今回は名前です
toStringメソッドで
personを名前以外のものに返すことを望まない限り
この実装は機能します
getFriends 메소드를 구현하는 방법이 또 있습니다.
person 클래스에 toString 메소드를 추가할 수 있습니다. 만약 toString
메소드가 이름을 리턴 한다면, getFriends 메소드를 전과 같이 구현할 수 있습니다.
이 코드가 전에 있던 코드고, 테스터를 다시 실행하면,
getFriends 메소드가 잘 작동하는 걸로 보입니다. 이런 이유는,
제가 toString을 freinds 배열 리스트에서 호출했을 때, 각각의
toString 메소드를 이용해서 이름을 가져옵니다.
이 구현은 잘 작동합니다. 단지 person 객체
안에 있는 이름만 가져올 수 있게 됩니다.