티스토리 뷰
JamesClass.java
package com.jwsoft.javaproject;
public class JamesClass<J> {
private J j;
public void set(J j) {
this.j = j;
}
public J get() {
return this.j;
}
}
MainActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
JamesClass<String> james = new JamesClass<>();
james.set("James Kim");
Log.e("result : ", james.get());
}
}
ConvertInterface.java
package com.jwsoft.javaproject;
public interface ConvertInterface<S, I> {
I convertToInteger(S s);
S convertToString(I i);
}
ConvertClass.java
package com.jwsoft.javaproject;
public class ConvertClass implements ConvertInterface<String, Integer> {
@Override
public Integer convertToInteger(String s) {
return Integer.parseInt(s);
}
@Override
public String convertToString(Integer i) {
return Integer.toString(i);
}
}
MainActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ConvertInterface<String, Integer> convert = new ConvertClass();
int i = convert.convertToInteger("30");
String s = convert.convertToString(30);
Log.e("ConvertToInteger : ", Integer.toString(i));
Log.e("ConvertToString : ", s);
}
}
JamesClass.java
package com.jwsoft.javaproject;
import java.util.List;
public class JamesClass {
public static <T> List<T> addListItem(List<T> list, T item) {
list.add(item);
return list;
}
}
MainActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> list = new ArrayList<>();
list.add("A");
for (int i=0; i<list.size(); i++) {
Log.e("", "Before : " + list.get(i));
}
JamesClass.addListItem(list, "B");
JamesClass.addListItem(list, "C");
for (int i=0; i<list.size(); i++) {
Log.e("", "After : " + list.get(i));
}
}
}
WildCardClass.java
package com.jwsoft.javaproject;
import java.util.ArrayList;
import java.util.List;
public class WildCardClass {
public static List<? extends Object> getObjectArrayList() {
return new ArrayList<>();
}
}
MainActivity.java
package com.jwsoft.javaproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<String> listString = (ArrayList<String>) WildCardClass.getObjectArrayList();
listString.add("A");
listString.add("B");
for (int i=0; i<listString.size(); i++) {
Log.e("listString : ", listString.get(i));
}
List<Integer> listInteger = (ArrayList<Integer>) WildCardClass.getObjectArrayList();
listInteger.add(10);
listInteger.add(20);
for (int i=0; i<listInteger.size(); i++) {
Log.e("listInteger : ", Integer.toString(listInteger.get(i)));
}
}
}
'Android > Java' 카테고리의 다른 글
[Java] Thread.join() (0) | 2020.07.27 |
---|---|
[Java] Synchronized (0) | 2020.07.27 |
[Java] MVVM (0) | 2020.07.23 |
[Java] RecyclerView + ItemClickListener + ItemLongClickListener (0) | 2020.07.21 |
[Java] AlertDialog (0) | 2020.07.21 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- coroutine
- James Kim
- JSONArray
- ViewModel
- recyclerview
- TabLayout
- fragment
- 혀가 길지 않은 개발자
- JSONObject
- handler
- 자바
- java
- Kotlin
- 안드로이드
- Design Pattern
- DataBinding
- CoordinatorLayout
- Architecture Pattern
- Vue.js #Vue.js + javascript
- View
- MVVM
- ArrayList
- 코틀린
- Android
- ViewPager2
- 안드로이드 #코틀린 #Android #Kotlin
- activity
- Intent
- XML
- Livedata
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함