[ Flutter ] Collection & Generic

κ²°Β·2023λ…„ 11μ›” 29일
0

Mobile-Software

λͺ©λ‘ 보기
15/15
post-thumbnail

πŸ₯˜ Collection

데이터듀을 λͺ¨μ•„μ„œ 가지고 μžˆλŠ” 자료ꡬ쑰

πŸ§‘β€πŸ³ Generic

Collection 이 가지고 μžˆλŠ” λ°μ΄ν„°λ“€μ˜ 데이터 νƒ€μž…μ„ 지정
μ½”λ“œμ˜ μ•ˆμ •μ„± 확보 및 μ½”λ“œμ˜ μž¬μ‚¬μš©μ„± μ—…


λ‹€λ₯Έ μ–Έμ–΄μ—μ„œμ˜ λ°°μ—΄ == ν”ŒλŸ¬ν„°μ—μ„œ 리슀트
fixed-length list => 리슀트 λ‚΄μ˜ 데이터 κ°œμˆ˜κ°€ μ§€μ •ν•œ 개수만큼 올 수 μžˆλ‹€
growable list => 리슀트 λ‚΄μ˜ 데이터 개수 μ œν•œ μ—†μŒ


void main(){
	var number1 = new List();
    
    // number λŠ” List νƒ€μž…
    // 리슀트 λ‚΄ λ‹€μ–‘ν•œ νƒ€μž…μ˜ 데이터듀이 λ“€μ–΄μ˜¬ 수 있음
    List number2 = new List();
    number2.add(2);
    number2.add('test');
    number2.add(7.4);
    print(number);
}


  • dynamic -> μ—¬λŸ¬ νƒ€μž…μ΄ 올 수 μžˆλ‹€!
void main(){
	List<dynamic> number = new List();
    List<int> number2 = new List();
    List<String> number2 = new List();
}

  • 가급적 νƒ€μž…μ„ dynamic 으둜 μ§€μ •ν•˜μ§€ 말고, ꡬ체적으둜 지정해쀄 것!
class Circle {}

class Square {}

class SquareSlot {
  insert(Square sqareSlot) {}
}

class CircleSlot {
  insert(Circle circleSlot) {}
}

void main() {
  var circleSlot = new CircleSlot();
  circleSlot.insert(new Circle());

  var squareSlot = new SquareSlot();
  squareSlot.insert(new Circle());
}

class Circle {}

class Square {}

class SquareSlot {
  insert(Square sqareSlot) {}
}

class CircleSlot {
  insert(Circle circleSlot) {}
}

class Slot<T> {
  insert(T shaape) {}
}

void main() {
  var circleSlot2 = new Slot<Circle>();
  circleSlot2.insert(new Circle());

  var squareSlot2 = new Slot<Square>();
  squareSlot2.insert(new Square());
}






πŸ“š μ½”λ”©μ…°ν”„ < ν”ŒλŸ¬ν„°(flutter) μˆœν•œλ§› κ°•μ’Œ >

0개의 λŒ“κΈ€