Reasoning about reflection, your thoughts

Hello all,
I would like to have your opinion about the following. To keep things simple, I'll explain my thoughts by referring to the interface java.util.List and the reverse(List) function in java.util.Collections.
Imagine you have some implementation of List (lets call this class SomeList), which can reverse the elements it holds on a quicker/better/more elegant/etc. way than the algorithm in Collections.reverse(). For example, SomeList can be built as a simply pointer-list, such that reversing the elements is simple a matter of swapping the head and tail-pointer.
In order to use the power of SomeList when it comes to reversing the elements, whitout having to move the reverse()-function from java.util.Collections to java.util.List (so Somelist can have it's own reverse() function, and ArrayList can use the general algorithm in AbstractList) (*), I thought about implementing java.util.Collections.reverse(List) as following:
public class Collections
  public static void reverse(List l)
     1) use reflection to check if the inputlist, l, has a function Collections_reverse();
     2)   if l has this function, call l.Collections_reverse()
     3)   if l hasn't this function, run the standard algorithm (the one currently in Collections.reverse()
}What do you think of this approach? By checking if the given input has a better implementation of the current function, users can override algorithms, even if these algorithms won't be called directly on the class itself. Is this a good use of reflection? Is this all possible? (this might be an odd question, but I don't have much experience with reflection)
(*) Indeed, I can simple move the reverse(List) function from java.util.Collections to java.util.List, but that doesn't look a good idea to me, since this would also be a reason to move java.util.Collections.sort(List), java.util.Collections.shuffle(List), etc. which will result in an enormous, overloaded, non-simple List-interface at the end.
thanks a lot for your ideas,
Peter

Yeah, marker interfaces are related, however I did intend something different. What I want is to override functions from another class, and to call the overrided function by reflection. I'll give a simple example:
Assume you have an interface:
interface CollectionInterface<T>
     public boolean add(T o);
     public boolean remove(T o);
     public Iterator<T> iterator();
}Also you have a class with static funcions. For example:
class AlgorithmsOnCollections
     public static <T> int count(CollectionInterface<T> c, int dummy)
}Countinig the elements in a CollectionInterface is very easy: simply count the elements returned by the iterator:
class AlgorithmsOnCollections
     public static <T> int count(CollectionInterface<T> c)
          Iterator<T> it = c.iterator();
          int count = 0;
          while (it.hasNext())
               it.next();
               ++count;
          return count;
}However, most collections will have a private member size, which will be incremented/decremented on every add/remove call. AlgorithmsOnCollections has ofcourse no access to it. Therefor I thought about implementing count() as followed:
class AlgorithmsOnCollections
     public static <T> int count(CollectionInterface<T> c, int dummy)
          Method method = null;
          try
               method = c.getClass().getMethod("AlgorithmsOnCollections_count", int.class);
               return (Integer) method.invoke(c, dummy);
          catch (NoSuchMethodException e) // run standard, general-purpose algorithm
               Iterator<T> it = c.iterator();
               int count = 0;
               while (it.hasNext())
                    it.next();
                    ++count;
               return count;
          catch (IllegalAccessException e)
               throw new RuntimeException();
          catch (InvocationTargetException e)
               throw new RuntimeException();
}Subclasses/implementations of CollectionInterface can decide to 'have' (I'd rather not call it 'implement', since the function isn't in the interface - thats the whole point) the function AlgorithmsOnCollections_count(). If they have it, it will be called by AlgorithmsOnCollections.count(). If they don't have it, the elements will be counted by the iterator.
What do you think of this? Note that the example is very simple (there is no reason to place simple functions like count() in an external class).
Here is a fully working example:
import java.lang.reflect.*;
import java.util.*;
interface CollectionInterface<T>
     public boolean add(T o);
     public boolean remove(T o);
     public Iterator<T> iterator();
class SomeCollection1<T> implements CollectionInterface<T>
     private List<T> elements = new ArrayList<T>();
     public boolean add(T e) { return elements.add(e); }
     public boolean remove(T e) { return elements.remove(e); }
     public Iterator<T> iterator() { return elements.iterator(); }
     public int AlgorithmsOnCollections_count(int dummy) // !! not in CollectionInterface !!
          System.out.println("SomeCollection.count() called!");
          return elements.size();
class SomeCollection2<T> implements CollectionInterface<T>
     private List<T> elements = new ArrayList<T>();
     public boolean add(T e) { return elements.add(e); }
     public boolean remove(T e) { return elements.remove(e); }
     public Iterator<T> iterator() { return elements.iterator(); }
class AlgorithmsOnCollections
     public static <T> int count(CollectionInterface<T> c, int dummy)
          Method method = null;
          try
               method = c.getClass().getMethod("AlgorithmsOnCollections_count", int.class);
               return (Integer) method.invoke(c, dummy);
          catch (NoSuchMethodException e) // run standard, general-purpose algorithm
               Iterator<T> it = c.iterator();
               int count = 0;
               while (it.hasNext())
                    it.next();
                    ++count;
               return count;
          catch (IllegalAccessException e)
               throw new RuntimeException();
          catch (InvocationTargetException e)
               throw new RuntimeException();
public class Reflection
     public static void main(String[] args)
          CollectionInterface<Integer> c1 = new SomeCollection1<Integer>();
          CollectionInterface<Integer> c2 = new SomeCollection2<Integer>();
          c1.add(new Integer(10));
          c1.add(new Integer(4320));
          c2.add(new Integer(43));
          c2.add(new Integer(23));
          c2.add(new Integer(169));
          System.out.println(AlgorithmsOnCollections.count(c1, 75));
          System.out.println(AlgorithmsOnCollections.count(c2, 42));
}The output is:
SomeCollection.count() called!
2
3
Please let me you know your thoughts! Thanks,
Peter

Similar Messages

  • DW CS4 - Your thoughts!

    Hi, I currently own DW CS3 but find it not very user friendly. I am looking at DW CS4 but I was wondering if it is any more like Golive than DW CS3 or if it makes designing websites any more intuitive. Also is it easier to create CSS in DW CS4?
    Those of you who have made the transition from DW CS3 to DW CS4 tell me your thoughts fro the perspective of a GL user.
    Thanks!

    DWCS4 is better UI-wise than DWCS3 is. I've used GL since version 1 pre-adobe and still do, stick to GCS2, as I've not had the proper time to migrate sites and am waiting for MenuMachine in its next version.
    DW still (talking about CS4) has a long way to go before it comes to par with GoLive when it comes to smart objects (only have them for Photoshop files) and sitemanagement, but apart from that it is quite OK.
    As always when switching applications there is a threshold of learning and getting used to before becoming comfortable in the new application, but the basics of DW and GL are not all that different. it is all html and css under the hood no matter hwo you look at them. Personally I am waiting for MenuMachine before doing the migration. But I am more ready to do it with CS4 than I was with CS3.
    Go here
    http://www.adobe.com/devnet/dreamweaver/golive_migration/content/using_gmk_extension.html
    for how to make the jump with Dwcs4.

  • Windows 8 upgrading to pro from standard/single language edition pricing, whats your thought on this

    Hi All
    Being in the Tech industry and working day to day life of users issue i have noticed that, even though uncommon, i would need to upgrade from windows 8/8.1 to Pro, and my clients, with this general question, Why is it so expensive if i already got windows
    8, shouldnt it have most of the features and now we just buying the addons? Basic response is yes they are right but you're actually purchasing a WHOLE key and not a partial key from MS. But it does leave a section of question, why should i spend $118 - 140
    to upgrade to Pro when most of the features are already built in?
    Shouldnt microsoft upgrade the key and just install the missing features at a lower price ? e.g if single licensing is $90 and pro is $110, they charge u $20 instead of $110. I understand it about money and such, but i believe more people would upgrade to
    pro easier if the price was adjusted like that instead of it current strategic plan of a full price of Pro just to gain some basic features like Domain ability.
    Whats your thoughts? 
    Lee Snr Systems Adminstrator

    Hi,
    For windows 8.1 as an example, you need $99.99 to add the Windows 8.1 pro pack and get the
    Windows Media Center and the power of Windows 8.1 Pro.
    http://www.microsoftstore.com/store/msusa/en_US/pdp/Windows-8.1-Pro-Pack/productID.288392300
    As I know, Windows 8 pro has added some important features such as Hyper-V, GP, VHD, bitlocker, domain..etc which are essential for business management\small organization. 
    You can find the comparison list in the following link
    http://www.microsoft.com/en-us/windows/enterprise/products-and-technologies/windows-8-1/compare/default.aspx
    We don't have the "power" to change the price :) so I just want to share the links above with you and hope you can understand the value of Windows 8/8.1 pro.
    Yolanda Zhu
    TechNet Community Support

  • Importance of Keeping Large PSDs Organized - Your Thoughts

    I am curious how other visual design professionals out there feel about the importance of keeping large PSDs well organized. By large I mean files with hundreds of layers and layer groups. I always strive to keep my files neat and orderly. I always name my layers and organize related items into layer groups and I color code these items too. I do this not only for myself but for other designers who may potentially receive my files and need to revise them. I have found that the extra time required is minimal and the benefits are great. However, I have recently discovered that some very talented designers I am working with do not agree with my approach. Their output is great but their files are a mess (i.e. not a single layer is named and items in layer groups are completely unrelated) and as a result it takes longer to revise their work, even with using AutoSelect. As a manager of a visual design team in a past job I assured that everyone on the team took steps to keep their files organized. Not perfect, but organized none the less. Anyone on the team could easily work on other member's files and pretty much instantly be productive.
    What are your thoughts on this issue?
    Thanks,
    richol

    Smart Objects!
    Apart from that:
    A clear and persistent naming policy is desirable, but more important to me seems to be that files’ layers are actually structured efficiently and non-destructiveness is striven for.
    Have you ever had to handle files where adjustment layers were placed above pixel layers, then above that pixel layers for clone stamping or flattened layers for transformations or filtering, then adjustment layers again … and on and on?
    Having to put files like that from their heads onto their feet for further editing can be quite the challenge.
    Another thing is when people use adjustment layers or a bunch of layers of different blend modes to create shadows or glows for clipped objects – sometimes it does indeed provide for better results, but quite often it seems to be redundant but can serve to make the files’ use in other programs or color modes pretty close to impracticable.

  • Can you give me some reasons about why I need to buy an iPod touch 5.Although I have the iPhone ,iPod nano, iPad ,MacBook pro,I think the iPod touch 5 is so attractive that I can't help buying it at once.If I have it,what I can do with it,can you tell me?

    can you give me some reasons about why I need to buy an iPod touch 5.Although I have the iPhone ,iPod nano, iPad ,MacBook pro,I think the iPod touch 5 is so attractive that I can't help buying it at once.If I have it,what I can do with it,can you tell me?

    All I can say is that I REALLY like my Touch 4th gen because I have all sorts of capabilities in a small form: e-mail, web browsing, news, weather, books, magazines, etc. etc.  Plus lots and lots of apps out there, including so many free ones.  I use the Cloud a lot so it's great to have everything sync'd to my MacBookPro (e-mail, Evernote, Pocket, etc.)
    It would be easier, though, to do some of this, especially magazines, on the iPad mini, but, again, I love the small size of the Touch. 
    As for the 5th gen instead of the 4th, the fifth has Siri and the 3D feature in maps, which are great.  And I'm sure it's a lot faster in iOS 6 than the 4th gen.  And cool colors! 
    Don't know if this helps . . .

  • My ipod touch(4th gen) just recently had the iOS 5 update.bu for some reason about 80% of my music collection appears with no album artwork and doesnt play any songs.basically it has my music on their but wont let me access it? please help!

    My ipod touch(4th gen) just recently had the iOS 5 update.bu for some reason about 80% of my music collection appears with no album artwork and doesnt play any songs.basically it has my music on their but wont let me access it? please help!

    i have the same problem but i have ios 5.01. how do you unsync? please help, thanks

  • There is an icon in the upper right hand corner about test your internet connection speed. is this malware

    ''locking - dupe of https://support.mozilla.org/en-US/questions/976623''
    there is an icon in the upper right hand corner about test your internet connection speed. is this malware

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    Use a compressed image type like PNG or JPG to save the screenshot.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • What todo with those who keep on answering basic questions - Your thoughts?

    Hi Experts,
    I have been active in ABAP Development Forum and usually hit the abuse button around 50 times a day.
    And most of the cases is for posting queries which are very basic and can be searched in SCN or in any Search engine.
    Example: The specified item was not found.
    Subject : BAPI
    Question :
    >
    muralireddy manyam wrote:
    > whats the  difference between normal function module and bapi function module?
    Although this is the mistake of the poster, i can see around 5 - 10 replies for such posts in a few seconds. Most of the replies are posted with Copy + paste content from SAP documentation/ other sites, some link farms etc.
    What i feel is this type of replies only encourages other people to post such basic questions again and again.
    So i think a little amendment need to be added to the Forum guidelines prompting members not to post replies/links to basic questions which can be easily searched.
    What you people think of it? Your thoughts are welcome and i hope some moderator would be in a better position to answer this.
    Regards
    Karthik D

    Hi Karthik,
    Your BAPI example took a whack together with all it's answers and the other questions by the same lazy bones fresher.
    There is no real answer to your question, because more usable expert forums and keeping the quality up to standard is a constant thing. Each new batch of freshers brings new challenges with them, and new types of points-gaming, etc. So it is the journey which counts
    At other times some tollerance is also appropriate - for example when the person has language problems and is using a translator.
    But for the lazy bones who don't even have common sense, there is no SDN medication available. No amount of waiving the rules at them helps. The only think which can be done is to delete it on sight and try to catch them as early as possible.
    For this the folks who use the Abuse Reports button are the true heros of the forums, as it is impossible for moderators to be everywhere all the time.
    Cheers and thank again!
    Julius

  • Your thoughts on problems with flash websites on mac....

    Hi there,
    A client has asked me to put together some information on mac vs. pc and browser differences or problems someone might find on a flash site. I had originally thought flash was supposed to behave the same no matter what platform or browser, but apparently this is not the case?
    Anyhow, I am looking for your thoughts and experiences on this topic. Anything relevant would be very helpful.
    They did have a specific question they are also looking to answer as well-
    How to find the flash token and deleting for a Mac for registering a computer?
    and similarly ... Where to find the flash object on the operating system?
    Just looking at comments regarding flash websites here, not flash software
    Thanks so much for your help and advice!

    All sorted, did not realise that the internet plug ins check box had been unchecked some how.

  • Html5 and css3 your thoughts please!

    Hi everyone
    As it is July the 4th, I though I would ask a question that is nothing to do with dreamweaver or coding problems.
    Two years ago I posted this thread - http://forums.adobe.com/thread/457240, on the subject of html5/css3, and most people thought that it was too early to adopt these technologies except for 'early adoption' trial sites.
    So what does everyone think now that two years have passed?
    Are these still considered too new?
    Are you using html5 and/or css3 in your web sites?
    Is 'progressive enhancement' and/or 'graceful degradation' now a part of your design/coding strategy when using them?
    Is anyone using or experimenting with any of the 'newer' features such as the css3 flex-box model or in-line svg?
    Is IE6/7 still part of your 'it must look the same in all browsers' design philosophy, or are you now ignoring these browsers?
    Your thoughts and opinions, (not insults please) would be welcome, and if you wish to pose a question on how to use any of these the please do so in a separate thread. Also if anything is stopping you using html5/css3, then say what it is.
    There is no correct answer but, (5) points will be awarded for the 2 best discussions, because if someone takes time and thought in posting a reply, then some sort of reward should be available, (I did consider a bottle of wine but).
    PZ

    pziecina wrote:
    Are these still considered too new?
    In my opinion yes.
    Are you using html5 and/or css3 in your web sites? 
    Not yet but I have been looking at some basics of both in preparation to move across once I feel the time is right - 2015 I'll be retired.
    Is 'progressive enhancement' and/or 'graceful degradation' now a part of your design/coding strategy when using them?
    Nooooooooo! If corners are supposed to be round then square ones is'nt graceful gradation to me.
    Is anyone using or experimenting with any of the 'newer' features such as the css3 flex-box model or in-line svg?
    Nope....never heard of them.
    pziecina wrote:
    Is IE6/7 still part of your 'it must look the same in all browsers' design philosophy, or are you now ignoring these browsers?
    IE 7 definitely but I don't design to take into consideration IE 6 any longer.
    I'am  right! I'm right! Follow the leader or maybe not

  • Need your thoughts on being an ABAPer

    Hi all...it's been a month since i started my first job after i graduated. And so happen when i joined, the company is in the final stages of a SAP project. So for the time being, my boss wants me to do ABAP. So far, i've only managed to develop 2 programs (that luckily met the consultant's approval and was transported), tried to do a BADI (unsuccessfully, so had to give it back), did several MM-related stuff my senior assigned me to do and later, i'm suppose to conduct a training class for key users for MM.
    My boss mentioned that he wants me to do ABAP, MM and PM. I'm wondering...do you think its possible for me to cope with all that?
    And i want to know what would be required of me and what actually is part of my job when i start touching on MM and PM?
    I have no prior experience (in terms of application) in SAP, especially in MM and PM...however i did attend the course for ABAP Workbench (TAW 10 & 12)...but regrettably i failed in my first attempt (however, i'm saving up now so that i can re-attempt it again)...i'm starting to get worried...it being my first job and all...
    Just want to know your thoughts...especially those of you that have been doing SAP for many years...

    OK where do I start? It is not an easy question, particularly when this is your first job. You haven't experienced different avenues available out there. So getting stuck with one may be difficult. Also, you haven't told us what your background is and your interests are as far as a career is concerned.
    SAP started as an ERP solutions company and has amassed vast knowledge of business processes accross various industries. From being a single product company(R2 to R3), it has evolved into a multi-product company but eveything to do with business processes. All its products are catering to the needs of business around the world. So if your inclination is towards learning business processes and understanding the flavors of it and if you have a deep interest in keenly observing the trends in business, then SAP is the company to stick with. Now coming to ABAP: ABAP itself is evolving into a wholistic development software from being a purely business software. It is including the open standards of object oriented programming, yet not compromising on its core business enabling strengths. You can no longer take comfort in the fact that you know ABAP. You have to have basic knowledge of XML, HTML, Java etc as web browser is fast becoming the defactor UI for all applications.
    In order to be good in ABAP, you also need good foundation in databases and business processes. If you are technically oriented, it doesn't matter whether you are MM or PP focussed, because ABAP is ABAP. But still knowing what the business flow is, how producing something in PP effects inventory in MM and how a product moves from raw material to finished product to sales is also very important for being a successful ABAPer. After all you are using ABAP to provide business solutions and if you don't understand your requirement, then there is not point in knowing all the syntax that is there in ABAP.
    I can go on and on, but this needs to be an interactive one, so I will wait until you come back with more questions.
    Regards,
    Srinivas

  • Iphone 4 not receiving photo text messages - would welcome your thoughts

    Iphone 4 is receiving word texts but not photo texts - set up with MMS not imessage. Would welcome your thoughts.

    Initially it sounds like something with your backup data caused the issue with your new device but if you restored your device again without using the backup and the issue still exists it wouldn't appear to be the issue at all. Since the problem seems to only be with one person are you sure it's not an issue on their end and with their network that is stopping you from receiving the messages? Have you tried *228 option 2 to see if that helps?

  • How would you go about retrieving your backed up data?

    How would you go about retrieving your backed up data from the Time Capsule?
    I have mine on auto back up (initial back up took 3 days)

    Time Machine FAQ

  • Error Msg, What are your thoughts

    I have not done any upgrades. The error follows below. I was just running safari and other small programs. Nothing I would consider unstable or taxing. What are your thoughts to the error?
    panic(cpu 0 caller 0x00350082): mbuf address out of range 0x954208
    Backtrace, Format - Frame : Return Address (4 potential args on stack)
    0xbcc3b04 : 0x128b5e (0x3bc46c 0xbcc3b28 0x131bbc 0x0)
    0xbcc3b44 : 0x350082 (0x3dbeb8 0x954208 0x0 0x13f5f5)
    0xbcc3b64 : 0x22e7e7 (0x1 0x2 0xbcc3b74 0xbcc3b74)
    0xbcc3c44 : 0x22bc65 (0x33cc858 0x1dbd0800 0x1 0x46000a0a)
    0xbcc3e14 : 0x22217b (0x1dbd0800 0x14 0xbcc3f14 0x20bf29d3)
    0xbcc3e54 : 0x223bff (0x1dbd0800 0x14 0x6 0x0)
    0xbcc3f64 : 0x21125d (0x1dbd0800 0x1dbd0800 0x42db5c 0x135798)
    0xbcc3fa4 : 0x1f7871 (0x2d52404 0x1dbd0800 0x1da5e816 0x1)
    0xbcc3fd4 : 0x197b19 (0x0 0x0 0x2653920 0x4a2000) Backtrace terminated-invalid frame pointer 0x0
    Kernel version:
    Darwin Kernel Version 8.7.1: Wed Jun 7 16:19:56 PDT 2006; root:xnu-792.9.72.obj~2/RELEASE_I386
    Model: MacBookPro1,1, BootROM MBP11.0055.B03, 2 processors, Intel Core Duo, 2 GHz, 512 MB
    Graphics: ATI Radeon X1600, ATY,RadeonX1600, PCIe, 128 MB
    Memory Module: DIMM1/BANK 1, 512 MB, DDR2 SDRAM, 667 MHz
    AirPort: spairportwireless_card_type_airportextreme (0x168C, 0x86), 0.1.24
    Bluetooth: Version 1.7.5f10, 2 service, 1 devices, 1 incoming serial ports
    Network Service: Built-in Ethernet, Ethernet, en0
    Network Service: AirPort, AirPort, en1
    Serial ATA Device: ST98823AS, 74.53 GB
    Parallel ATA Device: MATSHITADVD-R UJ-857
    USB Device: Hub, Up to 480 Mb/sec, 500 mA
    USB Device: Hub in Apple Pro Keyboard, Mitsumi Electric, Up to 12 Mb/sec, 500 mA
    USB Device: Apple Pro Keyboard, Mitsumi Electric, Up to 12 Mb/sec, 250 mA
    USB Device: USB Gaming Mouse, Logitech, Up to 12 Mb/sec, 500 mA
    USB Device: Built-in iSight, Micron, Up to 480 Mb/sec, 500 mA
    USB Device: IR Receiver, Apple Computer, Inc., Up to 12 Mb/sec, 500 mA
    USB Device: Apple Internal Keyboard / Trackpad, Apple Computer, Up to 12 Mb/sec, 500 mA
    USB Device: Bluetooth HCI, Up to 12 Mb/sec, 500 mA

    It sounds like it might be the Airport-related kernel panics that I and some others have had. Mine were fixed completely by a logic board replacement.
    To narrow the problem down, I found that I could test by downloading large files, many at a time, and get a kernel panic while on Airport, usually within a few minutes, always within an hour. Downloading the same large files while connected via Ethernet wouldn't result in a kernel panic. I could stay online for 24 hours on Ethernet, keeping the computer active by loading pages with webcams (that automatically refresh periodically) without ever getting a kernel panic, while I couldn't connect via Airport for anywhere near that length of time without getting a kernel panic. So I was as certain as one can be that the problem was caused by Airport.
    After doing some basic troubleshooting (resetting the PMU, repairing permissions) and even an erase and reinstall of Mac OS X, I called AppleCare with this information and described what I had tested. I would recommend doing the same to narrow down the problem and, if it's the same Airport-related kernel panic issue I had, arrange for a repair.

  • Have you experience a problem about losing your internet after downloading itunes? How to fix it?

    Have you experience a problem about losing your internet after downloading itunes? How to fix it?

    - Try cleaning out/blowing out the headphone jack. Try inserting/removing the plug a dozen times or so.
    Try the following to rule out a software problem
    - Reset the iPod. Nothing will be lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iPod.
    - Make an appointment at the Genius Bar of an Apple store. Seems you have a bad headphone jack.
    Apple Retail Store - Genius Bar
    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours.
    Apple - iPod Repair price
    A third-party place like the following will replace the jack for less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens
    Replace the jack yourself

Maybe you are looking for