Search Results

Search found 63799 results on 2552 pages for 'case class'.

Page 18/2552 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Static nested class visibility issue with Scala / Java interop

    - by Matt R
    Suppose I have the following Java file in a library: package test; public abstract class AbstractFoo { protected static class FooHelper { public FooHelper() {} } } I would like to extend it from Scala: package test2 import test.AbstractFoo class Foo extends AbstractFoo { new AbstractFoo.FooHelper() } I get an error, "class FooHelper cannot be accessed in object test.AbstractFoo". (I'm using a Scala 2.8 nightly). The following Java compiles correctly: package test2; import test.AbstractFoo; public class Foo2 extends AbstractFoo { { new FooHelper(); } } The Scala version also compiles if it's placed in the test package. Is there another way to get it to compile?

    Read the article

  • Java interface and abstract class issue

    - by George2
    Hello everyone, I am reading the book -- Hadoop: The Definitive Guide, http://www.amazon.com/Hadoop-Definitive-Guide-Tom-White/dp/0596521979/ref=sr_1_1?ie=UTF8&s=books&qid=1273932107&sr=8-1 In chapter 2 (Page 25), it is mentioned "The new API favors abstract class over interfaces, since these are easier to evolve. For example, you can add a method (with a default implementation) to an abstract class without breaking old implementations of the class". What does it mean (especially what means "breaking old implementations of the class")? Appreciate if anyone could show me a sample why from this perspective abstract class is better than interface? thanks in advance, George

    Read the article

  • Python 2.6, 3 abstract base class misunderstanding

    - by Aaron
    I'm not seeing what I expect when I use ABCMeta and abstractmethod. This works fine in python3: from abc import ABCMeta, abstractmethod class Super(metaclass=ABCMeta): @abstractmethod def method(self): pass a = Super() TypeError: Can't instantiate abstract class Super ... And in 2.6: class Super(): __metaclass__ = ABCMeta @abstractmethod def method(self): pass a = Super() TypeError: Can't instantiate abstract class Super ... They both also work fine (I get the expected exception) if I derive Super from object, in addition to ABCMeta. They both "fail" (no exception raised) if I derive Super from list. I want an abstract base class to be a list but abstract, and concrete in sub classes. Am I doing it wrong, or should I not want this in python?

    Read the article

  • Flash CS, reference root from external class

    - by Lotus
    Hi, I made this class and I put it in the same package of Timeline.as (the Document Class): package { import flash.utils.Timer; import flash.events.TimerEvent; public class Counter2 extends Timer { public function Counter2(delay:Number, repeatCount:int=0) { super(delay, repeatCount); super.addEventListener(TimerEvent.TIMER, timerHandler); } public override function start():void { super.start(); } public override function stop():void { super.stop(); } public function timerHandler(evt:TimerEvent) { trace(evt.target.currentCount); } } } This class is instanciated in Timeline.as constructor. Is there any way to reference Timeline(root) from this class? And, if so, how? Thanks!

    Read the article

  • Passing values from action class to model class in symfony

    - by THOmas
    I have a action class for saving some data to a database.In action class iam getting a id through url.I have to save the id in table. I am getting the id by $request-getParameter('id') I used this code for saving $this-form-bind($request-getParameter('question_answers')); if ($this-form-isValid()) { $this-form-save(); $this-redirect('@homepage'); } in model class i used a override save method to save extra field public function save(Doctrine_Connection $conn = null) { if ($this-isNew()) { $now=date('Y-m-d H:i:s', time()); $this->setPostedAt($now); } return parent::save($conn); so i want to get the id value here . So how can i pass id value from action class to model class is any-other way to save the id in action class itself Thanks in advance

    Read the article

  • what is the exact difference between PHP static class and singleton class

    - by Saif Bechan
    I have always used a Singleton class for a registry object in PHP. As all Singleton classes I think the main method looks like this: class registry { public static function singleton() { if( !isset( self::$instance ) ) { self::$instance = new registry(); } return self::$instance; } public function doSomething() { echo 'something'; } } So whenever I need something of the registry class I use a function like this: registry::singleton()->doSomethine(); Now I do not understand what the difference is between creating just a normal static function. Will it create a new object if I just use a normal static class. class registry { public static function doSomething() { echo 'something'; } } Now I can just use: registry::doSomethine(); Can someone explain to me what the function is of the singleton class. I really do not understand this.

    Read the article

  • Rails 3 ActiveModel Nested Class I18n

    - by Dave
    Given the following class definition in ruby: class Conversation class Message include ActiveModel::Validations attr_accessor :quantity validates :quantity, :presence => true end end How can you use i18n to customize to error message. For example the correct lookup for the class Conversation would be activemodel: errors: models: conversation: attributes: quantity: blank: "Some custom message" But what is it for the Message class? I tried: activemodel: errors: models: conversation: message: attributes: quantity: blank: "Some custom message" activemodel: errors: models: message: attributes: quantity: blank: "Some custom message" activemodel: errors: models: conversation::message: attributes: quantity: blank: "Some custom message" None of them work Any ideas or is this a bug with ActiveModel or I18n?

    Read the article

  • jQuery: selecting by class after class change by .addClass() or .attr()

    - by Sosh
    I have some jQuery code something like this: $(document).ready(function() { $("img.off").click(function() { alert('on'); $(this).attr('class', 'on'); }); $("img.on").click(function() { alert('off'); $(this).attr('class', 'off'); }); }); The selector works fine for images that have the class name defined in the original HTML document, however after manipulating the class name with jQuery, the img item will not respond to selectors using it's new class. In other words, running the above code, if you click an 'off' img, it will trigger the first function, and change the class to 'on'. However, clicking this image again does not trigger the second function (as I would have expected), but rather triggers the first again. It's as if the selector is reading the old DOM rather than the updated version. What am I doing wrong here? Firefox 3.6.3 - jQuery 1.4.2

    Read the article

  • Class Property in for each

    - by KoolKabin
    Hi guys, I am running from a problem while iterating over class properties. I have my first class: class Item private _UIN as integer = 0 private _Name as string = "" private _Category as ItemCategory = new ItemCategory() public Property UIN() as integer public property Name() as string public property Category() as ItemCategory end class Now when i iterate over the class properties from following code Dim AllProps As System.Reflection.PropertyInfo() Dim PropA As System.Reflection.PropertyInfo dim ObjA as object AllProps = new Item().getType().getProperties() for each propA in AllProps ObjA = PropA.GetValue(myObj, New Object() {}) debug.write ObjA.GetType().Name next I get UIN, Name, ItemCategory but i expected UIN, Name and Category. I am a bit unclear about this and dun know why this is happening? What should i do to correct it?

    Read the article

  • can this keyword be used in an abstract class in java

    - by Reddy
    I tried with below example, it is working fine. I expected it to pick sub-class's value since object won't be created for super class (as it is abstract). But it is picking up super class's field value only. Please help me understand what is the concepts behind this? abstract class SuperAbstract { private int a=2; public void funA() { System.out.println("In SuperAbstract: this.a "+a); } } class SubClass extends SuperAbstract { private int a=34; } I am calling new SubClass.funA(); I am expecting it to print 34, but it is printing 2.

    Read the article

  • C# private (hidden) base class

    - by Loadmaster
    It is possible to make a C# base class accessible only within the library assembly it's compiled into, while making other subclasses that inherit from it public? For example: using System.IO; class BaseOutput: Stream // Hidden base class { protected BaseOutput(Stream o) { ... } ...lots of common methods... } public class MyOutput: BaseOutput // Public subclass { public BaseOutput(Stream o): base(o) { ... } public override int Write(int b) { ... } } Here I'd like the BaseOutput class to be inaccessible to clients of my library, but allow the subclass MyOutput to be completely public. I know that C# does not allow base classes to have more restrictive access than subclasses, but is there some other legal way of achieving the same effect?

    Read the article

  • can the keyword 'this' be used in an abstract class in java

    - by Reddy
    I tried with below example, it is working fine. I expected it to pick sub-class's value since object won't be created for super class (as it is abstract). But it is picking up super class's field value only. Please help me understand what is the concepts behind this? abstract class SuperAbstract { private int a=2; public void funA() { System.out.println("In SuperAbstract: this.a "+a); } } class SubClass extends SuperAbstract { private int a=34; } I am calling new SubClass.funA(); I am expecting it to print 34, but it is printing 2.

    Read the article

  • php: two objects from the same class work independent of each other

    - by user317563
    Good morning, I would like the code in my controller to look something like this: <?php $class = new sanitizeInput() $string1 = $class -> input($_POST[name]) -> mysql_escape(); $string2 = $class -> input($_POST[age]) -> mysql_escape(); print " String1: $string1 <br /> String2: $string2" ?> It seems with my sanitizeInput class, any change to $string2 is applied to $string1. What ways can I change this? I would preferably like to make the changes within the class to make my controller as easily read as possible. Thank you for your time. Kind regards, Marius

    Read the article

  • I cant put a string in a switch nor an array in a class

    - by TimothyTech
    Okay, im making a pretty big file in my opinion, so i wanted to separate it into several files for cleaner code. so i have my main .cpp file and two header files holding my classes. well the header files dont hold strings, it aboslutely wont budge. i call the library in both my .cpp file and even tried it in my header file. another issue i ran into is using strings to make switches function, reason being if i use integers in a switch if the user inputs a alphabetical character the program goes into an endless loop. string choice; switch (choice) { case "1" : //... break; case "2" : //... break; } and my last issue is when i create an object in a case it gives an error. says cross initialization of object. string choice; switch (choice) { case "1" : Class object; break; case "2" : //... break; }

    Read the article

  • Python metaclass to run a class method automatically on derived class

    - by Barry Steyn
    I want to automatically run a class method defined in a base class on any derived class during the creation of the class. For instance: class Base(object): @classmethod def runme(): print "I am being run" def __metclass__(cls,parents,attributes): clsObj = type(cls,parents,attributes) clsObj.runme() return clsObj class Derived(Base): pass: What happens here is that when Base is created, ''runme()'' will fire. But nothing happens when Derived is created. The question is: How can I make ''runme()'' also fire when creating Derived. This is what I have thought so far: If I explicitly set Derived's metclass to Base's, it will work. But I don't want that to happen. I basically want Derived to use the Base's metaclass without me having to explicitly set it so.

    Read the article

  • Use of class definitions inside a method in Java

    - by Bragaadeesh
    Hi public class TestClass { public static void main(String[] args) { TestClass t = new TestClass(); } private static void testMethod(){ class TestMethodClass{ int a; int b; int c; } TestMethodClass testMethodClass = new TestMethodClass(); } } I found out that the above piece of code is perfectly legal in Java. I have the following questions. What is the use of ever having a class definition inside a method? Will a class file be generated for TestMethodClass Its hard for me to imagine this concept in an Object Oriented manner. Having a class definition inside a behavior. Probably can someone tell me with equivalent real world examples. Thanks

    Read the article

  • Ojective C Class or struct?

    - by Scott Pendleton
    I have a class Song with properties Title, Key, Artist, etc. There are no methods. I loop through a database of song information and create a Song object for each, populating the properties, and then store the Song objects in an NSArray. Then I thought, why not just have a struct Song with all those same properties instead of a class Song. Doing so would eliminate the class files, the #import Song line in the using class's .m file, and the need to alloc, init, release. On the other hand, I'd have to put the struct definition in every class that might need it. (Unless there's some globally accessible location -- is there?) Also, can a struct be stored in an NSArray?

    Read the article

  • templated class : accessing derived normal-class methods

    - by user1019129
    I have something like this : class Container1 { public: method1() { ... } } class Container2 { public: method1() { ... } } template<class C = Container1> class X : public C { public: using C::method1(); ..... X(string& str) : C(str) {}; X& other_method() { method1(); ...; } } My question is why I have to use "using C::method1()", to be able to access the method.. Most of answers I found is for the case where templated-class inhering templated-class. Normally they mention using "this-", but this does not seem to work in this case. Can I do something else shorter... Also I'm suspecting the other error I'm getting is related to the same problem : no match call for (X<Container1>) (<std::string&>)

    Read the article

  • Dynamic Class Inheritance For PHP

    - by VirtuosiMedia
    I have a situation where I think I might need dynamic class inheritance in PHP 5.3, but the idea doesn't sit well and I'm looking for a different design pattern to solve my problem if it's possible. Use Case I have a set of DB abstraction layer classes that dynamically compiles SQL queries, with one DAL class for each DB type (MySQL, MsSQL, Oracle, etc.). Each table in the database has its own class that extends the appropriate DAL class. The idea is that you interact with the table classes, but never directly use the DAL class. If you want to support a different DB type for your app, you don't need to rewrite any queries or even any code, you simply change a setting that swaps one DAL class out for another...and that's it. To give you a better idea of how this is used, you can take a look at the DAL class, the table classes, and how they are used on this StackExchange Code Review page. To really understand what I'm trying to do, please take a look at my implementation first before suggesting a solution. Issues The strategy that I had used previously was to have all of the DAL classes share the same class name. This eliminated autoloading, so I had to manually load the appropriate DAL class in a switch statement. However, this approach presents some problems for testing and documentation purposes, so I'd like to find a different way to solve the problem of loading the correct DAL class more elegantly. Update to clarify the issue The problem basically boils down to inconsistencies in the class name (pre-PHP 5.3) or class namespace (PHP 5.3) and its location in the directory structure. At this point, all of my DAL classes have the same name, DBObject, but reside in different folders, MySQL, Oracle, etc. My table classes all extend DBObject, but which DBObject they extend varies depending on which one has been loaded. Basically, I'm trying to have my cake and eat it too. The table classes act as a stable API and extend a dynamic backend, the DAL (DBObject) classes. It works great, but I outsmarted myself and because of the inconsistencies with the class names and their locations, I can't autoload the DBObject, which makes running unit tests and generating API docs impossible for the DBObject classes because the tests and docs rely on auto-loading. Just loading the appropriate DBObject into memory using a factory method won't work because there will be times when I need to load multiple DBObjects for testing. Because the classes currently share a name, this causes a class is already defined error. I can make exceptions for the DBObjects in my test code, obviously, but I'm looking for something a little less hacky as there may future instances where something similar would need to be done. Solutions? Worst case scenario, I can continue my current strategy, but I don't like it very much, especially as I'll soon be converting my code to PHP 5.3. I suspect that I can use some sort of dynamic inheritance via either namespaces (preferred) or a dynamic class extension, but I haven't been able to find good examples of this implemented in the wild. In your answers, please suggest either an alternate pattern that would work for this use case or an example of dynamic inheritance done right. Please assume PHP 5.3 with namespaced code. Any code examples are greatly encouraged. The preferred constraints for the solution are: DAL class can be autoloaded. DAL classes don't share the same exact same namespace, but share the same class name. As an example, I would prefer to use classes named DbObject that use namespaces like Vm\Db\MySql and Vm\Db\Oracle. Table classes don't have to be rewritten with a change in DB type. The appropriate DB type is determined via a single setting only. That setting is the only thing that should need to change to interchange DB types. Ideally, the setting check should occur only once per page load, but I'm flexible on that.

    Read the article

  • NHibernate DuplicateMappingException when mapping abstract class and subclass

    - by stiank81
    I have an abstract class, and subclasses of this, and I want to map this to my database using NHibernate. I'm using Fluent, and read on the wiki how to do the mapping. But when I add the mapping of the subclass an NHibernate.DuplicateMappingException is thrown when it is mapping. Why? Here are my (simplified) classes: public abstract class FieldValue { public int Id { get; set; } public abstract object Value { get; set; } } public class StringFieldValue : FieldValue { public string ValueAsString { get; set; } public override object Value { get { return ValueAsString; } set { ValueAsString = (string)value; } } } And the mappings: public class FieldValueMapping : ClassMap<FieldValue> { public FieldValueMapping() { Id(m => m.Id).GeneratedBy.HiLo("1"); // DiscriminateSubClassesOnColumn("type"); } } public class StringValueMapping : SubclassMap<StringFieldValue> { public StringValueMapping() { Map(m => m.ValueAsString).Length(100); } } And the exception: NHibernate.MappingException : Could not compile the mapping document: (XmlDocument) ---- NHibernate.DuplicateMappingException : Duplicate class/entity mapping NamespacePath.StringFieldValue Any ideas?

    Read the article

  • UML class diagram vs ER database diagram

    - by salva84
    Hi, I'm a little confused, I'm developing a program, the program consist in two parts, the server and the clients, there are groups, places, messages... stored in the server, and the clients has to connect with it. I've design the use cases diagram, the activity diagrams, and I have design the class diagram too. The thing is that I want to implement the server in a mysql tables for storing the users, groups, places... users in groups... so I've designed a E-R diagram consisting in 6 tables, but the problem is that I think that my class diagram and my ER diagram looks too similar, I mean, I think I'm not doing things right because I have a class for each table practically, and when I have to extract all the users on my system, do I have to convert all the rows into objects at first and write in the database for each object modified? The easy choice for me would be to base my whole application only in the database, and making a class to extract and insert data in it, but I have to follow the UML specification and I'm a little confused what to do with the class diagram, because the books I have read say that I have to create a class for each "entity" of my program. Sorry for my bad English. Thank you.

    Read the article

  • Visibility of Class field-data of Mouse Clicked ImageButton located within WrapPanel

    - by Bill
    I am attempting to obtain the class-data behind an ImageButton that is mouse-clicked; which ImageButton is located within a WrapPanel filled with ImageButtons. The problem I am having is obtaining the visibility of the field data within the class behind the image-button. Although I can see the class, I can neither see nor access the field data. Can anyone please point me in the right direction? // Handles the ImageButton mouseClick event within the WrapPanel. private void SolarSystem_Click(Object sender, RoutedEventArgs e) { FrameworkElement fe = e.OriginalSource as FrameworkElement; SelectedPlanet PlanetSelected = new SelectedPlanet(fe); PlanetSelected.Owner = this; MessageBox.Show(PlanetSelected.PlanetName); } // Used to initiate instance of Class and some field data. public SelectedPlanet(FrameworkElement fe) { InitializeComponent(); string sPlanetName = ((PlanetClass)(fe)).PlanetName; return sPlanetName } // Class Data public class PlanetClass { string planetName; public PlanetClass(string planetName) { PlanetName = planetName; } public string PlanetName { set { planetName = value; } get { return planetName; } } }

    Read the article

  • documenting class properties

    - by intuited
    I'm writing a lightweight class whose properties are intended to be publicly accessible, and only sometimes overridden in specific instantiations. There's no provision in the Python language for creating docstrings for class properties, or any sort of properties, for that matter. What is the accepted way, should there be one, to document these properties? Currently I'm doing this sort of thing: class Albatross(object): """A bird with a flight speed exceeding that of an unladen swallow. Properties: """ flight_speed = 691 __doc__ += """ flight_speed (691) The maximum speed that such a bird can attain """ nesting_grounds = "Throatwarbler Man Grove" __doc__ += """ nesting_grounds ("Throatwarbler Man Grove") The locale where these birds congregate to reproduce. """ def __init__(**keyargs): """Initialize the Albatross from the keyword arguments.""" self.__dict__.update(keyargs) Although this style doesn't seem to be expressly forbidden in the docstring style guidelines, it's also not mentioned as an option. The advantage here is that it provides a way to document properties alongside their definitions, while still creating a presentable class docstring, and avoiding having to write comments that reiterate the information from the docstring. I'm still kind of annoyed that I have to actually write the properties twice; I'm considering using the string representations of the values in the docstring to at least avoid duplication of the default values. Is this a heinous breach of the ad hoc community conventions? Is it okay? Is there a better way? For example, it's possible to create a dictionary containing values and docstrings for the properties and then add the contents to the class __dict__ and docstring towards the end of the class declaration; this would alleviate the need to type the property names and values twice. I'm pretty new to python and still working out the details of coding style, so unrelated critiques are also welcome.

    Read the article

  • Java: extending Object class

    - by Fabio F.
    Hello, I'm writing (well, completing) an "extension" of Java which will help role programming. I translate my code to Java code with javacc. My compilers add to every declared class some code. Here's an example to be clearer: MyClass extends String implements ObjectWithRoles { //implements... is added /*Added by me */ public setRole(...){...} public ... /*Ends of stuff added*/ ...//myClass stuff } It adds Implements.. and the necessary methods to EVERY SINGLE CLASS you declare. Quite rough, isnt'it? It will be better if I write my methods in one class and all class extends that.. but.. if class already extends another class (just like the example)? I don't want to create a sort of wrapper that manage roles because i don't want that the programmer has to know much more than Java, few new reserved words and their use. My idea was to extends java.lang.Object.. but you can't. (right?) Other ideas? I'm new here, but I follow this site so thank you for reading and all the answers you give! (I apologize for english, I'm italian)

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >