您好,我是一名學生,我有一個問題。我有兩節課:
class User{
String uid;
String name;
byte[] upicture;
String pversion ;
public User(String uid,
String name,
byte[] upicture, String pversion ){
this.uid=uid;
this.name=name;
this.upicture=upicture;
this.pversion=pversion;
}
....
我有一個帶有 ArrayList 的 Model_user.class:
ublic class Model_user {
private static Model_user theinstance = null;
private ArrayList<User> user_list;
public static synchronized Model_user getInstance() {
if (theinstance == null) {
theinstance = new Model_user();
}
和一個班級帖子:
class Post{
String comment;
String author;
Post(String comment, String author) {
this.comment = comment;
this.author = author;
}
....
我有一個帶有 ArrayList 的 Model_post.class:
ublic class Model_user {
private static Model_user theinstance = null;
private ArrayList<Post> user_list;
public static synchronized Model_post getInstance() {
if (theinstance == null) {
theinstance = new Model_post();
}
如何將帖子鏈接到用戶?如何與用戶一起查看帖子?我可以在 Model_post 中創建兩個陣列,一個用于帖子,一個用于用戶嗎?我可以使用 ArrayList<User,Post> 嗎?
uj5u.com熱心網友回復:
您的示例中的一種方法是創建User以下屬性Post:
class Post{
String comment;
User author;
Post(String comment, User author) {
this.comment = comment;
this.author = author;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/487042.html
