methods

Changing the visibility scope of parent methods in child classes

孤人 提交于 2019-12-25 04:24:45
问题 I've got a Validator class and a UserValidator class which extends from it. My Validator has a public method setRule(...) with public visibility. When I extend from it I want to change the visibility of the setRule(...) parent method to private/protected within the child so that it's only visible for the child and no outsiders can call this method from the child. Is that possible? If so, how could I achieve it? 回答1: From an architectural point of view this is not recommended. As already

implementation of linked list inside hash table

会有一股神秘感。 提交于 2019-12-25 04:22:38
问题 i am learning data structures and so far have seen linked list,binary tress, and hash tables. I am trying to find a general way to approach a practice problem in which it gives me freedom to use these data structures to solve it. I was hoping to receive some feedback on the best way to solve this problem. The problem tells me to read two files, one file with all the classes and pre-requisites needed to complete a degree and another file that has all classes that have been completed and figure

Interface can not call self method

被刻印的时光 ゝ 提交于 2019-12-25 04:14:11
问题 I have defined two functions. When I pass a pointer to it, I can't get the defined method. Why is this? type Visitor interface { work() } func test(v *Visitor) { v.work() // error } func test1(v Visitor) { v.work() // ok } Error: v.work undefined (type *Visitor is pointer to interface, not interface) anyone know why, ths 回答1: func test(v *Visitor) { v.work() // error } v.work() ought to be a method call. But v is of type *Visitor , a pointer to interface. A pointer to interface has 0 methods,

How do i make the variables from main method work on begin method?

懵懂的女人 提交于 2019-12-25 04:07:08
问题 I am trying to make the user inputs from the main method work on the begin method to create the size of a box in the canvas so it would create different sizes when different inputs are used This is what i have so far: import objectdraw.*; import java.awt.*; import java.util.Scanner; public class Ricochet extends WindowController { private static final int CANVAS_WIDTH=400; private static final int CANVAS_HEIGHT=600; public static void main(String [] args) { Scanner scnr = new Scanner(System

MethodNotAllowedHttpException on resource defined method Laravel-4

折月煮酒 提交于 2019-12-25 03:59:08
问题 I created a very simple form so that I could use a submit button rather than a link to open up an edit users page. Using a link works perfectly, but the form button fails and yields a MethodNotAllowedHttpException even though the method ("edit") is perfectly defined in the UsersController resource and otherwise works fine. Route: Route::resource('users','UsersController'); UsersController: public function edit($id) { $user = $this->user->find($id); return View::make('users.edit')->with('user'

How to count current level missed_days?

给你一囗甜甜゛ 提交于 2019-12-25 03:43:41
问题 How can we call something like this <%= habit.current_level.missed_days %> where we only call the missed_days from the current_level , instead of all the missed_days in a habit (to just give an general idea of what we want). For example if two boxes are checked, calling <%= habit.missed_days %> in the habits index will show 2 and if eight boxes are checked it will show 8 , but the goal here is that even if 8 boxes are checked: it will still only say 2 strikes in the index because we are

How to check an input against many different potential options, each with a separate output in Java?

試著忘記壹切 提交于 2019-12-25 03:38:16
问题 Currently I'm trying to make a program that will ask for an input of an element from the periodic table, and then output some information about that element. My original idea was to create a method for it and then just call the method a bunch of times with the different information for each element, but I now see why that won't work since, if I have the method for Lithium first, it will only accept an input of Lithium. How could I accomplish this without just having a ton of nearly-identical

objective-c (iphone sdk) access instance method from separate class

吃可爱长大的小学妹 提交于 2019-12-25 03:26:09
问题 I know this is a pretty well posted thing to do, but I still can't work it out. I have an instance method saveAllDataJobs in Jobs.m. - (void) saveAllDataJobs { ... } I am in DetailViewController.m and I want to run the method saveAllDataJobs, which is in Jobs.m. What precisely do I need in order for this code to run. Sorry for the repeat question, but I can't work it out. Regards 回答1: Read about "delegation" in documents. Here is the basics: When you create DetailViewController, you give it

How do I improve regex to eliminate unnecessary method chaining?

微笑、不失礼 提交于 2019-12-25 03:06:42
问题 This functional method takes a number and returns the same value separated with commas, as is the common convention in the US. The only way I could get it to work with regex was to reverse the string before and after the expression. Is there a regex that can help me eliminate the need to call String#reverse twice for method functionality? def separate_comma(number) raise "You must enter a number." if number.is_a?(Numeric) == false number.to_s.reverse.gsub(/(\d{3})(?=\d{1,3})/, "\\1,").reverse

Error in a static method in a inner class [duplicate]

旧巷老猫 提交于 2019-12-25 02:46:15
问题 This question already has answers here : Why can't we have static method in a (non-static) inner class? (14 answers) Closed 5 years ago . Im trying to understand how inner class works and while experimenting with some simple code i got a error : The method hello cannot be declared static; static methods can only be declared in a static or top level type on this code public class Class1 { public static void main(String[] args) { Class1 c = new Class1(); c.show(); } public static void show() {