Search Results

Search found 4035 results on 162 pages for 'extends'.

Page 4/162 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How do i change Object to String in a class which extends AsyncTask?

    - by Filip V.
    I'm learning from Google's Android developing tutorial and i came across a problem. On this link https://developer.android.com/training/basics/network-ops/connecting.html#AsyncTask it says to create a class that extends AsyncTask. So when i write the class it automatically implements the method as follows: private Object doInBackground(Object... args) {..} //it's fine but when i try writing just as it says in the tutorial: private String doInBackground(String... args) {..} //it gives an error and the error says: The method doInBackground(String...) of type MainActivity.DownloadWebpageText must override a superclass method. So how do i change Object to String without getting an error there?

    Read the article

  • how to use multiple $_name using extends Zend_Db_Table_Abstract in zend frame work.

    - by karthik
    we tried to do like this,but it is showing some errors.Our table names are users and messages. <?php class Application_Model_childconnect1 extends Zend_Db_Table_Abstract { protected $_name = 'users'; public function loginvalidation($username,$pwd) { $row = $this->fetchRow('UserName = \'' . $username . '\'and UserPW = \''. $pwd . '\''); if (!$row) { $msg="invalid"; return $msg; } else { return $row->toArray(); } } protected $_name = 'messages'; public function replymessage($message) { $data=array( 'MessageText'=>$message ); $this->insert($data); } }

    Read the article

  • PHP class extends not working why and is this how to correctly extend a class?

    - by Matthew
    Hi so I'm trying to understand how inherteince works in PHP using object oriented programming. The main class is Computer, the class that is inheriting is Mouse. I'm extedning the Computer class with the mouse class. I use __construct in each class, when I istinate the class I use the pc type first and if it has mouse after. For some reason computer returns null? why is this? class Computer { protected $type = 'null'; public function __construct($type) { $this->type = $type; } public function computertype() { $this->type = strtoupper($this->type); return $this->type; } } class Mouse extends Computer { protected $hasmouse = 'null'; public function __construct($hasmouse){ $this->hasmouse = $hasmouse; } public function computermouse() { if($this->hasmouse == 'Y') { return 'This Computer has a mouse'; } } } $pc = new Computer('PC', 'Y'); echo $pc->computertype; echo $pc->computermouse;

    Read the article

  • ORM framework that extends base class with database-implementation.

    - by aioobe
    I have a game consisting of a client / server + a webpage. A central notion in both client and game-/webserver is an Account. Accounts are stored in a database thus I'm in need of some ORM and recently had a look at Hibernate and Cayenne. My understanding however, is that both frameworks provide an "DatabaseBackedAccount"-class which I extend with my other Account methods. My problem is that the Account class is reused heavily on the client side, and I would obviously not want to include database-related code on the client implementation. My current solution is to have an Account class (shared by server and client) and extend this with a DatabaseBackedAccount (overriding setter-methods and providing a commit method) on the server side. I find this quite natural and nice, however I've had to implement all gory sql-details and ORM myself. Is there any way to "turn the table" in any existing ORM framework, so that the generated classes extend my existing class?

    Read the article

  • Why can't I pass an object of type T to a method on an object of type <? extends T>?

    - by Matt
    In Java, assume I have the following class Container that contains a list of class Items: public class Container<T> { private List<Item<? extends T>> items; private T value; public Container(T value) { this.value = value; } public void addItem(Item item) { items.add(item); } public void doActions() { for (Item item : items) { item.doAction(value); } } } public abstract class Item<T> { public abstract void doAction(T item); } Eclipse gives the error: The method doAction(capture#1-of ? extends T) in the type Item is not applicable for the arguments (T) I've been reading generics examples and various postings around, but I still can't figure out why this isn't allowed. Eclipse also doesn't give any helpful tips in its proposed fix, either. The variable value is of type T, why wouldn't it be applicable for ? extends T?.

    Read the article

  • Scala factory pattern returns unusable abstract type

    - by GGGforce
    Please let me know how to make the following bit of code work as intended. The problem is that the Scala compiler doesn't understand that my factory is returning a concrete class, so my object can't be used later. Can TypeTags or type parameters help? Or do I need to refactor the code some other way? I'm (obviously) new to Scala. trait Animal trait DomesticatedAnimal extends Animal trait Pet extends DomesticatedAnimal {var name: String = _} class Wolf extends Animal class Cow extends DomesticatedAnimal class Dog extends Pet object Animal { def apply(aType: String) = { aType match { case "wolf" => new Wolf case "cow" => new Cow case "dog" => new Dog } } } def name(a: Pet, name: String) { a.name = name println(a +"'s name is: " + a.name) } val d = Animal("dog") name(d, "fred") The last line of code fails because the compiler thinks d is an Animal, not a Dog.

    Read the article

  • Getting all inner classes by reflection

    - by Roman
    I have the following problem. I have this pretty class and now I want to get all the classes that extend that class (inner classes ) and fill 'classList' with it. ( in an automatic way of course ) public abstract class CompoundReference { private static List<Class<? extends CompoundReference>> classList = new ArrayList<Class<? extends CompoundReference>>(); @CompoundKey(gsType = User.class, dbType = UserDetailsMappings.class) public static class CUser extends CompoundReference { } @CompoundKey(gsType = Catalog.class, dbType = CatalogDetailsMappings.class) public static class CCatalog extends CompoundReference { } @CompoundKey(gsType = Product.class, dbType = ProductDetailsMappings.class) public static class CProduct extends CompoundReference { } @CompoundKey(gsType = Category.class) public static class CCategory extends CompoundReference { } @CompoundKey(gsType = Poll.class, dbType = PollDetailsMappings.class) public static class CPoll extends CompoundReference { } // much mroe inner classes Some manual solution would be just to main such a static block , that is something that I dont want to do. static { classList.addAll(Arrays.asList(CUser.class, CCatalog.class, CProduct.class, CCategory.class, CPoll.class, CComment.class, CWebPage.class, CReview.class, CPost.class, CMessage.class, CStory.class,CPicture.class)); }

    Read the article

  • trait implementation

    - by Jeriho
    If I have some traits like: trait A {...} trait B extends A{...} trait C1 extends B{...} trait C2 extends A{...} I can write class in two ways (C1 and C2 add same functionality) class Concrete1 extends B with C1 class Concrete2 extends B with C2 What variant is better(efficient)?

    Read the article

  • Compile error on inheritance of generic inner class extending with bounds

    - by Arne Burmeister
    I have a problem when compiling a generic class with an inner class. The class extends a generic class, the inner class also. Here the interface implemented: public interface IndexIterator<Element> extends Iterator<Element> { ... } The generic super class: public abstract class CompoundCollection<Element, Part extends Collection<Element>> implements Collection<Element> { ... protected class CompoundIterator<Iter extends Iterator<Element>> extends ImmutableIterator<Element> { ... } } The generic subclass with the compiler error: public class CompoundList<Element> extends CompoundCollection<Element, List<Element>> implements List<Element> { ... private class CompoundIndexIterator extends CompoundIterator<IndexIterator<Element>> implements IndexIterator<Element> { ... } } The error is: type parameter diergo.collect.IndexIterator<Element> is not within its bound extends CompoundIterator<IndexIterator<Element>> ^ What is wrong? The code compiles with eclipse, but bot with java 5 compiler (I use ant with java 5 on a mac and eclipse 3.5). No, I cannot convert it to a static inner class.

    Read the article

  • java generics and the addAll method

    - by neesh
    What is the correct type of argument to the addAll(..) method in Java collections? If I do something like this: Collection<HashMap<String, Object[]>> addAll = new ArrayList<HashMap<String, Object[]>>(); // add some hashmaps to the list.. currentList.addAll(newElements); //currentList is of type: List<? extends Map<String, Object[]>> I understand I need to initialize both variables. However, I get a compilation error (from eclipse): Multiple markers at this line - The method addAll(Collection<? extends capture#1-of ? extends Map<String,Object[]>>) in the type List<capture#1-of ? extends Map<String,Object[]>> is not applicable for the arguments (List<capture#2-of ? extends Map<String,Object[]>>) - The method addAll(Collection<? extends capture#1-of ? extends Map<String,Object[]>>) in the type List<capture#1-of ? extends Map<String,Object[]>> is not applicable for the arguments (Collection<HashMap<String,Object[]>>) what am I doing wrong?

    Read the article

  • Problem with 2 levels of inheritance in hibernate mapping

    - by Seth
    Here's my class structure: class A class B extends A class C extends A class D extends C class E extends C And here are my mappings (class bodies omitted for brevity): Class A: @Entity @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @MappedSuperclass @DiscriminatorColumn( name="className", discriminatorType=DiscriminatorType.STRING ) @ForceDiscriminator public abstract class A Class B: @Entity @DiscriminatorValue("B") public class B extends A Class C: @Entity @DiscriminatorValue("C") @MappedSuperclass @DiscriminatorColumn( name="cType", discriminatorType=DiscriminatorType.STRING ) @ForceDiscriminator public abstract class C extends A Class D: @Entity @DiscriminatorValue("D") public class D extends C Class E: @Entity @DiscriminatorValue("E") public class E extends C I've got a class F that contains a set of A: @Entity public class F { ... @OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL) @JoinTable( name="F_A", joinColumns = @JoinColumn(name="A_ID"), inverseJoinColumns = @JoinColumn(name="F_ID") ) private Set<A> aSet = new HashSet<A>(); ... The problem is that whenever I add a new E instance to aSet and then call session.saveOrUpdate(fInstance), hibernate saves with "A" as the discrimiator string. When I try to access the aSet in the F instance, I get the following exception (full stacktrace ommitted for brevity): org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: path.to.class.A Am I mapping the classes incorrectly? How am I supposed to map multiple levels of inheritance? Thanks for the help!

    Read the article

  • Self-type mismatch in Scala

    - by Alexey Romanov
    Given this: abstract class ViewPresenterPair { type V <: View type P <: Presenter trait View {self: V => val presenter: P } trait Presenter {self: P => var view: V } } I am trying to define an implementation in this way: case class SensorViewPresenter[T] extends ViewPresenterPair { type V = SensorView[T] type P = SensorPresenter[T] trait SensorView[T] extends View { } class SensorViewImpl[T](val presenter: P) extends SensorView[T] { presenter.view = this } class SensorPresenter[T] extends Presenter { var view: V } } Which gives me the following errors: error: illegal inheritance; self-type SensorViewPresenter.this.SensorView[T] does not conform to SensorViewPresenter.this.View's selftype SensorViewPresenter.this.V trait SensorView[T] extends View { ^ <console>:13: error: type mismatch; found : SensorViewPresenter.this.SensorViewImpl[T] required: SensorViewPresenter.this.V presenter.view = this ^ <console>:16: error: illegal inheritance; self-type SensorViewPresenter.this.SensorPresenter[T] does not conform to SensorViewPresenter.this.Presenter's selftype SensorViewPresenter.this.P class SensorPresenter[T] extends Presenter { ^ I don't understand why. After all, V is just an alias for SensorView[T], and the paths are the same, so how can it not conform?

    Read the article

  • Is this how dynamic language copes with dynamic requirement?

    - by Amumu
    The question is in the title. I want to have my thinking verified by experienced people. You can add more or disregard my opinion, but give me a reason. Here is an example requirement: Suppose you are required to implement a fighting game. Initially, the game only includes fighters, who can attack each other. Each fighter can punch, kick or block incoming attacks. Fighters can have various fighting styles: Karate, Judo, Kung Fu... That's it for the simple universe of the game. In an OO like Java, it can be implemented similar to this way: abstract class Fighter { int hp, attack; void punch(Fighter otherFighter); void kick(Fighter otherFighter); void block(Figther otherFighter); }; class KarateFighter extends Fighter { //...implementation...}; class JudoFighter extends Fighter { //...implementation... }; class KungFuFighter extends Fighter { //...implementation ... }; This is fine if the game stays like this forever. But, somehow the game designers decide to change the theme of the game: instead of a simple fighting game, the game evolves to become a RPG, in which characters can not only fight but perform other activities, i.e. the character can be a priest, an accountant, a scientist etc... At this point, to make it more generic, we have to change the structure of our original design: Fighter is not used to refer to a person anymore; it refers to a profession. The specialized classes of Fighter (KaraterFighter, JudoFighter, KungFuFighter) . Now we have to create a generic class named Person. However, to adapt this change, I have to change the method signatures of the original operations: class Person { int hp, attack; List<Profession> skillSet; }; abstract class Profession {}; class Fighter extends Profession { void punch(Person otherFighter); void kick(Person otherFighter); void block(Person otherFighter); }; class KarateFighter extends Fighter { //...implementation...}; class JudoFighter extends Fighter { //...implementation... }; class KungFuFighter extends Fighter { //...implementation ... }; class Accountant extends Profession { void calculateTax(Person p) { //...implementation...}; void calculateTax(Company c) { //...implementation...}; }; //... more professions... Here are the problems: To adapt to the method changes, I have to fix the places where the changed methods are called (refactoring). Every time a new requirement is introduced, the current structural design has to be broken to adapt the changes. This leads to the first problem. Rigid structure makes it hard for code reuse. A function can only accept the predefined types, but it cannot accept future unknown types. A written function is bound to its current universe and has no way to accommodate to the new types, without modifications or rewrite from scratch. I see Java has a lot of deprecated methods. OO is an extreme case because it has inheritance to add up the complexity, but in general for statically typed language, types are very strict. In contrast, a dynamic language can handle the above case as follow: ;;fighter1 punch fighter2 (defun perform-punch (fighter1 fighter2) ...implementation... ) ;;fighter1 kick fighter2 (defun perform-kick (fighter1 fighter2) ...implementation... ) ;;fighter1 blocks attacks from fighter2 (defun perform-block (fighter1 fighter2) ...implementation... ) fighter1 and fighter2 can be anything as long as it has the required data for calculation; or methods (duck typing). You don't have to change from the type Fighter to Person. In the case of Lisp, because Lisp only has a single data structure: list, it's even easier to adapt to changes. However, other dynamic languages can have similar behaviors as well. I work primarily with static languages (mainly C and Java, but working with Java was a long time ago). I started learning Lisp and some other dynamic languages this year. I can see how it helps improving my productivity.

    Read the article

  • Object desing problem for simple school application

    - by Aragornx
    I want to create simple school application that provides grades,notes,presence,etc. for students,teachers and parents. I'm trying to design objects for this problem and I'm little bit confused - because I'm not very experienced in class designing. Some of my present objects are : class PersonalData() { private String name; private String surename; private Calendar dateOfBirth; [...] } class Person { private PersonalData personalData; } class User extends Person { private String login; private char[] password; } class Student extends Person { private ArrayList<Counselor> counselors = new ArrayList<>(); } class Counselor extends Person { private ArrayList<Student> children = new ArrayList<>(); } class Teacher extends Person { private ArrayList<ChoolClass> schoolClasses = new ArrayList<>(); private ArrayList<Subject> subjects = new ArrayList<>(); } This is of course a general idea. But I'm sure it's not the best way. For example I want that one person could be a Teacher and also a Parent(Counselor) and present approach makes me to have two Person objects. I want that user after successful logging in get all roles that it has (Student or Teacher or (Teacher & Parent) ). I think I should make and use some interfaces but I'm not sure how to do this right. Maybe like this: interface Role { } interface TeacherRole implements Role { void addGrade( Student student, Grade grade, [...] ); } class Teacher implements TeacherRole { private Person person; [...] } class User extends Person{ ArrayList<Role> roles = new ArrayList<>(); } Please if anyone could help me to make this right or maybe just point me to some literature/article that covers practical objects design.

    Read the article

  • OOP beginner: classB extends classA. classA already object. method in classB needed.. etc.

    - by Yvo
    Hey guys, I'm learning myself to go from function based PHP coding to OOP. And this is the situation: ClassA holds many basic tool methods (functions). it's __construct makes a DB connection. ClassB holds specific methods based on a certain activity (extract widgets). ClassB extends ClassA because it uses some of the basic tools in there e.g. a database call. In a php file I create a $a_class = new ClassA object (thus a new DB connection). Now I need a method in ClassB. I do $b_class = new ClassB; and call a method, which uses a method from it's parent:: ClassA. In this example, i'm having ClassA 'used' twice. Onces as object, and onces via a parent:: call, so ClassA creates another DB connection (or not?). So what is the best setup for this basic classes parent, child (extend) situation? I only want to make one connection of course? I don't like to forward the object to ClassB like this $b_class = new ClassB($a_object); or is that the best way? Thanks for thinking with me, and helping :d

    Read the article

  • Collections of generics

    - by Luis Sep
    According to what I've read, I think this can't be done, but I'd like to be sure. I have a class OpDTO and several other *DTO extends OpDTO. Then, I want to have a method to extract just certain elements from lists of these child DTOs, and return the extracted elements in another list: public List<? extends OpDTO> getLastOp (List<? extends OpDTO> listDTOs) { List<? extends OpDTO> last = new ArrayList<? extends OpDTO>(); //compile error: Cannot instantiate the type ArrayList<? extends OpDTO> //processing return last; } I want ult to be a list of elements of the same kind as elements in listDTOs, and use only OpDTO's methods, but it produces a compile error: Cannot instantiate the type ArrayList<? extends OpDTO> I also tried doing something like: public <T> List<T> getLastOp (List<T> listDTOs) { List<T> last = new ArrayList<T>(); //processing return last; } But then I can't enforce elements in listDTOs to be a subclass of OpDTO, and can't instantiate T. Any idea?

    Read the article

  • Scala passing type parameters to object

    - by Shahzad Mian
    In Scala v 2.7.7 I have a file with class Something[T] extends Other { } object Something extends OtherConstructor[Something] { } This throws the error: class Something takes type parameters object Something extends OtherConstructor[Something] { However, I can't do this object Something[T] extends OtherConstructor[Something[T]] { } It throws an error: error: ';' expected but '[' found. Is it possible to send type parameters to object? Or should I change and simply use Otherconstructor

    Read the article

  • Java: Why is this Subclass valid?

    - by incrediman
    Here, I have an abstract class: abstract class A<E extends A> { abstract void foo(E x); } Here's a class that extends A: class B extends A<B>{ void foo(B x){} } And here's another (E is B here on purpose): class C extends A<B>{ void foo(B x){} } Both of those classes are valid, and the reasoning for that makes sense to me. However what confuses me is how this could possibly be valid: class D extends A{ void foo(A x){} } Since when are generics optional like that? I thought the extending class (subclass) of A would be required to specify an E?

    Read the article

  • is it wasteful/bad design to use a vector/list where in most instances it will only have one element

    - by lucid
    is it wasteful/bad design to use a vector/list where in most instances it will only have one element? example: class dragon { ArrayList<head> = new ArrayList<head> Heads; tail Tail = new tail(); body Body = new body(); dragon() { theHead=new head(); Heads.add(theHead); } void nod() { for (int i=0;i<Heads.size();i++) { heads.get(i).GoUpAndDown(); } } } class firedragon extends dragon { } class icedragon extends dragon { } class lightningdragon extends dragon { } // 10 other one-headed dragon declarations here class hydra extends dragon { hydra() { anotherHead=new head(); for (int i=0;i<2;i++) { Heads.add(anotherHead); } } } class superhydra extends dragon { superhydra() { anotherHead=new head(); for (int i=0;i<4;i++) { Heads.add(anotherHead); } } }

    Read the article

  • Unexpected generics behaviour

    - by pronicles
    I found strange generics behaviour. In two words - thing I realy want is to use ComplexObject1 in most general way, and the thing I realy missed is why defined generic type(... extends BuisnessObject) is lost. The discuss thread is also awailable in my blog http://pronicles.blogspot.com/2010/03/unexpected-generics-behaviour.html. public class Test { public interface EntityObject {} public interface SomeInterface {} public class BasicEntity implements EntityObject {} public interface BuisnessObject<E extends EntityObject> { E getEntity(); } public interface ComplexObject1<V extends SomeInterface> extends BusinessObject<BasicEntity> {} public interface ComplexObject2 extends BuisnessObject<BasicEntity> {} public void test(){ ComplexObject1 complexObject1 = null; ComplexObject2 complexObject2 = null; EntityObject entityObject1 = complexObject1.getEntity(); //BasicEntity entityObject1 = complexObject1.getEntity(); wtf incompatible types!!!! BasicEntity basicEntity = complexObject2.getEntity(); } }

    Read the article

  • Scala - Enumeration vs. Case-Classes

    - by tzofia
    I've created akka actor called LogActor. The LogActors's receive method handling messages from other actors and logging them to the specified log level. I can distinguish between the different levels in 2 ways. The first one: import LogLevel._ object LogLevel extends Enumeration { type LogLevel = Value val Error, Warning, Info, Debug = Value } case class LogMessage(level : LogLevel, msg : String) The second: (EDIT) abstract class LogMessage(msg : String) case class LogMessageError(msg : String) extends LogMessage(msg) case class LogMessageWarning(msg : String) extends LogMessage(msg) case class LogMessageInfo(msg : String) extends LogMessage(msg) case class LogMessageDebug(msg : String) extends LogMessage(msg) Which way is more efficient? does it take less time to match case class or to match enum value? (I read this question but there isn't any answer referring to the runtime issue)

    Read the article

  • Avoiding NPE in trait initialization without using lazy vals

    - by 0__
    This is probably covered by the blog entry by Jesse Eichar—still I can't figure out how to correct the following without residing to lazy vals so that the NPE is fixed: Given trait FooLike { def foo: String } case class Foo( foo: String ) extends FooLike trait Sys { type D <: FooLike def bar: D } trait Confluent extends Sys { type D = Foo } trait Mixin extends Sys { val global = bar.foo } First attempt: class System1 extends Mixin with Confluent { val bar = Foo( "npe" ) } new System1 // boom!! Second attempt, changing mixin order class System2 extends Confluent with Mixin { val bar = Foo( "npe" ) } new System2 // boom!! Now I use both bar and global very heavily, and therefore I don't want to pay a lazy-val tax just because Scala (2.9.2) doesn't get the initialisation right. What to do?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >